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

混江龙づ霸主 提交于 2019-12-11 17:52:28

问题


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


来源:https://stackoverflow.com/questions/48873638/how-do-i-move-a-user-to-a-specific-channel-on-discord-using-the-discord-py-api

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