【问题标题】:How a discord bot can join a voice channel in discord rewrite?不和谐机器人如何在不和谐重写中加入语音频道?
【发布时间】:2019-12-08 15:47:45
【问题描述】:

当我输入!join 时,我想让我的不和谐机器人连接到我所在的语音频道。 我试图用下面的代码来做,但我得到了这个错误: bot: BotInstance of 'Bot' has no 'voice_client_int' memberpylint(no-member)

我发现我的代码与 rewrite discord 版本不兼容。

@bot.command(pass_context = True)
async def join(ctx):
        channel = ctx.message.author.voice.voice_channel
        await bot.join_voice_channel(channel)
@bot.command(pass_context = True)
async def leave(ctx):
        server = ctx.message.server
        voice_client = bot.voice_client_int(server)
        await voice_client.disconnect()

有人可以帮我吗?

【问题讨论】:

标签: python discord discord.py discord.py-rewrite


【解决方案1】:

如迁移页面所述,在重写版本中,语音连接现在是VoiceChannel 模型的一种方法。 pass_context 也被弃用,因为现在总是传递上下文。

现在看起来像这样:

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

当然,这个过于简化的版本缺少错误处理。

【讨论】:

  • await voice_channel.connect() 只是为我挂起,没有任何反应。知道我做错了什么吗?
  • AttributeError: 'User' 对象没有属性 'voice'。
猜你喜欢
  • 2020-10-15
  • 2021-05-23
  • 2019-06-24
  • 2020-10-08
  • 2023-04-05
  • 2021-09-30
  • 2021-03-14
  • 1970-01-01
  • 2019-04-04
相关资源
最近更新 更多