如何使用 discord.py API 将用户移动到 discord 上的特定频道

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

好的,所以我知道执行此操作的命令,但我的问题是我不知道要传递给参数的参数是什么。我希望我的代码获取用户的消息内容,然后将用户移动到名为 "afk" 的语音频道。这是我的代码片段:

我想做的就是将键入单词 !move 的用户移动到另一个语音频道。 如果我的代码不好,我很抱歉,但我只需要这个。

我知道您可能需要查看我的定义,但仅此而已:

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 从服务器频道列表中获取频道。

channel = discord.utils.find(lambda x: x.name == 'afk', message.server.channels)
await client.move_member(message.author, channel)

一些进一步的说明:

  • 以上对于afk频道来说其实是不必要的,因为服务器有一个Server.afk_channel属性。
  • 您还应该使用 discord.ext.commands 扩展来执行您的命令,以防止您的 on_message 变得混乱。