Python 使不和谐机器人在语音频道上说些什么
我找不到解决办法,所以我来了。 我在discord.py rewrite中为我的discord服务器制作了一个bot,我想实现一个功能,当用户加入语音频道时,我的bot会说些什么 我甚至不能让机器人加入语音聊天,因为它会给出所有可能的错误。提前谢谢 这就是我所尝试的:Python 使不和谐机器人在语音频道上说些什么,python,discord,bots,discord.py,discord.py-rewrite,Python,Discord,Bots,Discord.py,Discord.py Rewrite,我找不到解决办法,所以我来了。 我在discord.py rewrite中为我的discord服务器制作了一个bot,我想实现一个功能,当用户加入语音频道时,我的bot会说些什么 我甚至不能让机器人加入语音聊天,因为它会给出所有可能的错误。提前谢谢 这就是我所尝试的: @bot.command() async def join_voice(self, ctx): connected = ctx.author.voice if connected: await co
@bot.command()
async def join_voice(self, ctx):
connected = ctx.author.voice
if connected:
await connected.channel.connect()
还有这个
@bot.command(pass_context=True)
async def join(ctx):
author = ctx.message.author
channel = author.voice_channel
await bot.join_voice_channel(channel)
他们都给出了这个错误
discord.ext.commands.errors.CommandInvokeError: Command raised an exception:
AttributeError: 'Member' object has no attribute 'voice_channel'
尝试使用语音支持安装discord.py:
# Linux/macOS
python3 -m pip install -U "discord.py[voice]"
# Windows
py -3 -m pip install -U discord.py[voice]
解决方案
好的,大消息。我找到了连接的方法。
你需要有我没有安装的PyNaCl
我还进行了一些调试,发现作者中不存在voice_频道,我将其替换为voice.channel
@bot.command()
async def join(ctx):
author = ctx.message.author
channel = author.voice.channel
await channel.connect()
print("i'm in the voice channel")
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
print("i'm out of the voice channel")
嗨,欢迎来到StackOverflow!对于您的问题,您是否可以包括一些您尝试过的代码以及可能出现的任何错误,以便我们可以更好地帮助您?谢谢,但它在两个命令中都给了我相同的错误。这一次,他们似乎都给出了相同的错误。我刚刚更新了帖子。