机器人可以't连接到语音频道-discord.py重写



我正在使用discord.py重写来制作一个discordbot,最近遇到了一个问题。

我已经发出了加入用户语音频道的命令。问题是,当我在本地电脑上运行命令时,它运行得很好,但现在我正试图在树莓派上运行它,当连接到语音频道时,它失败了。

我试过安装所有的依赖项,但就是无法正常工作。命令代码:

@bot.command()
async def join(ctx):
channel = ctx.message.author.voice.channel
voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
await ctx.send("I joined the channel!")

没有任何例外。

您使用了一种糟糕的方式连接到语音通道。请尝试使用此代码。

它识别用户所在的位置,并在该语音通道中进行连接。

@bot.command(name='join', invoke_without_subcommand=True)
async def join(ctx):
destination = ctx.author.voice.channel
if ctx.voice_state.voice:
await ctx.voice_state.voice.move_to(destination)
return

ctx.voice_state.voice = await destination.connect()
await ctx.send(f"Joined {ctx.author.voice.channel} Voice Channel")

您可以在终端中运行pip install -U discord.py[voice]。并尝试使用此代码。

@bot.command(pass_context = True)
async def join(ctx):
if (ctx.author.voice):
await ctx.author.voice.channel.connect()
else:
await ctx.send("Please Join Voice channel to run this command")
@client.command()
async def leave(ctx):
await ctx.voice_client.disconnect()

最新更新