問題描述
我想讓我的 discord 機器人在我輸入 !join
時連接到我所在的語音頻道.我試圖用下面的代碼來做,但我得到了這個錯誤: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)
我發現我的代碼與 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()
有人可以幫我嗎?
推薦答案
如遷移頁面所述,在重寫版本中,語音連接現在是 VoiceChannel
模型的一種方法.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.
這篇關于不和諧機器人如何在不和諧重寫中加入語音頻道?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!