问题
Okay, so I know the command to do this but my issue is I do not know what arguments to pass to the parameters. I want my code to take a user's message content and then move the user to a voice channel named "afk". Here is a snippet of my code:
All I want to do is move a user that types the words !move in any case to be moved to another voice channel. I am sorry if my code is bad but I just need this down.
I know you might need to see my definitions but all it is:
def on_message(message):
if '!MOVE' in message.content.upper():
author = message.author
voice_channel = id('afk')
await client.move_member(author, voice_channel)
回答1:
client.move_member takes two arguments: a Member and a Channel. We can use discord.utils.find to get the channel from the servers list of channels.
channel = discord.utils.find(lambda x: x.name == 'afk', message.server.channels)
await client.move_member(message.author, channel)
Some further notes:
- The above is actually unnecessary for the afk channel, as servers have a Server.afk_channel attribute.
- You should also be using the
discord.ext.commandsextension to implement your commands, to keep youron_messagefrom getting cluttered.
来源:https://stackoverflow.com/questions/48873638/how-do-i-move-a-user-to-a-specific-channel-on-discord-using-the-discord-py-api