How to change a channels name using discord.py v.1.0.0a?

妖精的绣舞 提交于 2019-12-29 08:25:26

问题


i've already searched a lot about this online. There I came across the API Refrence (https://discordpy.readthedocs.io/en/rewrite/api.html#discord.TextChannel) which kind of helped me finding what command I need to use. So my conculsion would be to use this code:

channel = client.get_channel(475772135730708480)
@client.command()
async def emoivb(ctx):
    await discord.VoiceChannel.edit(channel, name = "test")

the problem is that it doesnt work with this error:

File "C:/Users/MyUser/Desktop/discordbot.py", line 25, in emoivb
    await discord.VoiceChannel.edit(channel, name = "test")

So this error doesnt help me at all... but im sure I just didnt understand the API refrence correctly and didnt use the command as it is supposed to be used. Im pretty new to python coding so that is the most likely thing to have happended. If anyone has some more python knowledge and is able to understand what I did wrong I would really appreciate your help! :)


回答1:


The easier way would be to specify the target channel and name in the command, something like

@client.command()
async def emoivb(ctx, channel: discord.VoiceChannel, *, new_name):
    await channel.edit(name=new_name)

This isn't perfect though: For names with spaces you'll have to enclose the existing channel name in quotes

!rename "Old Channel" New Channel

This is because Discord doesn't support mentioning voice channels.



来源:https://stackoverflow.com/questions/51705898/how-to-change-a-channels-name-using-discord-py-v-1-0-0a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!