我正在尝试制作一个简单的Discord Bot(在Python 3中为Wirtten),该命令在命令执行后就可以连接和断开连接。连接命令可以正常工作,但我的Discconect命令不起作用。这是两个命令的代码片段:
async def join(message):
channel = message.message.author.voice.channel
await channel.connect()
@client.command(pass_context = True)
async def leave(message):
channel = message.message.author.voice.channel
await channel.disconnect()```
答案 0 :(得分:0)
尝试将您的leave
函数替换为:
@commands.command()
async def leave(ctx):
channel = ctx.message.author.voice.channel
voice = get(self.bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await ctx.send(f'Disconnecting from channel **{channel}**')
await voice.disconnect()
else:
await ctx.send("I'm not connected in any channel")