How do I move a user to a specific channel on discord using the discord.py API(如何使用 discord.py API 将用户移动到 discord 上的特定频道)
问题描述
好的,所以我知道执行此操作的命令,但我的问题是我不知道要传递给参数的参数.我希望我的代码获取用户的消息内容,然后将用户移动到名为afk"的语音频道.这是我的代码片段:
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:
我要做的就是将输入单词 !move 的用户移动到另一个语音频道.如果我的代码不好,我很抱歉,但我只是需要这个.
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 有两个参数:一个 Member 和一个 Channel.我们可以使用 discord.utils.find 从服务器频道列表中获取频道.
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)
一些进一步的说明:
- 对于 afk 频道,上述内容实际上是不必要的,因为服务器有一个
Server.afk_channel属性. - 您还应该使用
discord.ext.commands扩展来实现您的命令,以防止您的on_message变得混乱.
- The above is actually unnecessary for the afk channel, as servers have a
Server.afk_channelattribute. - You should also be using the
discord.ext.commandsextension to implement your commands, to keep youron_messagefrom getting cluttered.
这篇关于如何使用 discord.py API 将用户移动到 discord 上的特定频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 discord.py API 将用户移动到 discord 上的特定频道
基础教程推荐
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
