python - Discord 机器人如何加入 Discord Rewrite 中的语音 channel ?

标签 python discord discord.py

我想让我的不和谐机器人连接到我输入 !join 时所在的语音 channel 。 我尝试使用以下代码执行此操作,但出现此错误: bot:“Bot”的 BotInstance 没有“voice_client_int”memberpylint(no-member)

我发现我的代码与重写不和谐版本不兼容。

@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()

有人可以帮助我吗?

最佳答案

如迁移页面所述,在重写版本中,语音连接现在是 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()

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

关于python - Discord 机器人如何加入 Discord Rewrite 中的语音 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57285423/

相关文章:

python - Discord.py 我想在服务器名称旁边添加服务器图标

python - 是否可以在 dms 中使用斜杠命令来处理 discord py?

python - 使用子进程在没有 sudo 的情况下注销

python - 从 Python 中的字典中给函数默认参数

python - 将混合 dict 元素与 int、字符串和 float 进行比较

https - 为什么在ffmpeg中找不到https协议(protocol)?

python - 对此 Discord.py 重写 + react 灯代码感到困惑 - 需要解释

python - 使用 'dummy' 变量创建数学函数,以便稍后计算

python - 如何在嵌入消息中包含普通内容?

javascript - 获取当前用户在 Discord 服务器中的角色