我想让我的不和谐机器人连接到我输入 !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/