不和谐机器人如何在不和谐重写中加入语音频道?

How a discord bot can join a voice channel in discord rewrite?(不和谐机器人如何在不和谐重写中加入语音频道?)
本文介绍了不和谐机器人如何在不和谐重写中加入语音频道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想让我的 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.

这篇关于不和谐机器人如何在不和谐重写中加入语音频道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)