简体   繁体   中英

How do I move a user to a specific channel on discord using the discord.py API

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)

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.commands extension to implement your commands, to keep your on_message from getting cluttered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM