繁体   English   中英

不和谐的python bot离开命令不起作用

[英]discord python bot leave command not working

下面是用于加入和离开命令的代码。 加入工作正常,但离开没有。 在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 has left")应该可以很好地满足您的目的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM