【发布时间】:2021-11-24 22:33:22
【问题描述】:
我目前正在使用 discord.py 库编写一个机器人。 机器人(脚本)有什么方法可以自动将用户移动到不同的语音频道? 例如,您键入命令让用户 X 自动移动到特定的语音聊天,并且每次用户 X 加入语音频道时,他都会被移动。
【问题讨论】:
标签: python discord discord.py
我目前正在使用 discord.py 库编写一个机器人。 机器人(脚本)有什么方法可以自动将用户移动到不同的语音频道? 例如,您键入命令让用户 X 自动移动到特定的语音聊天,并且每次用户 X 加入语音频道时,他都会被移动。
【问题讨论】:
标签: python discord discord.py
你可以做到。只需使用on_voice_state_update 事件和move_to 函数。 例如:
@commands.Cog.listener() # for cogs. If you haven't implemented cogs use `@client.event`
async def on_voice_state_update(self, member, before, after): # also remove `self` argument if you haven't implemented cogs
if after.channel is not None: # check if member join to new voice channel
channel = something # you can specify voice channel here. For example use `self.client.get_channel(id)` to get channel by ID
await member.move_to(channel)
【讨论】: