【发布时间】:2021-01-31 00:04:04
【问题描述】:
如果用户不在语音频道中,我正在尝试让机器人发送错误消息。这是我到目前为止尝试过的方法,但它不起作用。
@commands.command()
async def join(self, ctx):
channel = ctx.message.author.voice.channel
voice = get(self.client.voice_clients, guild=ctx.guild)
try:
if voice and voice.is_connected():
await voice.move_to(channel)
await ctx.send(f'Moved to {channel}')
else:
voice = await channel.connect()
await ctx.send(f'Connected to {channel}')
except:
await ctx.send('You are not in a voice channel.')
【问题讨论】:
-
“不起作用”是什么意思?你有任何错误吗?您是否打印了任何变量以查看它们包含的内容?我最好的猜测是
voice实际上是None当他们不在频道中时,所以你不能请求它的channel属性。
标签: python asynchronous discord.py