下面是用于join和leave命令的代码。 加入工作正常,但离开则不行。在stackoverflow上尝试了许多解决方案,但没有一个起作用。
@commands.command(name='join')
async def join(self, ctx):
print('join command worked')
member = utils.find(lambda m: m.id == ctx.author.id, ctx.guild.members)
if member is not None and member.voice is not None:
vc = member.voice.channel
player = self.bot.music.player_manager.create(ctx.guild.id, endpoint=str(ctx.guild.region))
if not player.is_connected:
player.store('channel', ctx.channel.id)
await self.connect_to(ctx.guild.id, str(vc.id))```
@commands.command(pass_context=True)
async def leave(ctx):
if (ctx.guild.voice_client):
await ctx.guild.voice_client.disconnect()
await message.channel.send('Bot has left')
else:
await ctx.channel.send("I'm not in a voice channel, use join command to add me.")```
Any possible solutions?
Thanks
答案 0 :(得分:0)
看起来变量message
在当前作用域中不存在:仅使用ctx.send("Bot has left")
应该可以正常工作。