discord python bot leave命令不工作

discord python bot leave命令不工作,python,audio,discord,discord.py,Python,Audio,Discord,Discord.py,下面是用于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 i

下面是用于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

看起来变量
message
在当前范围内不存在:仅使用
ctx.send(“Bot已离开”)
就可以正常工作