問題描述
我想讓我的 discord 機(jī)器人在我輸入 !join
時(shí)連接到我所在的語音頻道.我試圖用下面的代碼來做,但我得到了這個(gè)錯(cuò)誤: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)
我發(fā)現(xiàn)我的代碼與 rewrite discord 版本不兼容.
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()
有人可以幫我嗎?
推薦答案
如遷移頁面所述,在重寫版本中,語音連接現(xiàn)在是 VoiceChannel
模型的一種方法.pass_context
也被棄用,因?yàn)楝F(xiàn)在總是傳遞上下文.
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.
現(xiàn)在看起來像這樣:
@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()
當(dāng)然,這個(gè)過于簡(jiǎn)化的版本缺少錯(cuò)誤處理.
Of course this oversimplified version lacks error handling.
這篇關(guān)于不和諧機(jī)器人如何在不和諧重寫中加入語音頻道?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!