问题描述
当我输入!join
时,我想使不和谐的bot连接到我所在的语音通道。
i尝试使用以下代码执行此操作,但出现此错误:
bot:'Bot'的BotInstance没有'voice_client_int'memberpylint(no-member)
I want to make my discord bot to connect to the voice channel I am when I type !join
.i have tried to do it with the following code but i got this error:bot: BotInstance of 'Bot' has no 'voice_client_int' memberpylint(no-member)
我发现我的代码与重写不和谐版本不兼容。
i found that my code is not compatible with the rewrite discord version.
@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 $的一种方法。 c $ c>模型。
pass_context
也被弃用,因为现在总是通过上下文。
As stated in the migrating page, in the rewrite version, the voice connection is now a method of the VoiceChannel
model.The pass_context
is also deprecated as context is now always passed.
现在看起来像这样:
@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()
当然,这个过于简化的版本缺乏错误处理。
Of course this oversimplified version lacks error handling.
这篇关于不和谐的机器人如何在不和谐重写中加入语音通道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!