无法连接到语音通道

无法连接到语音通道

本文介绍了Bot 无法连接到语音通道 - discord.py 重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用 discord.py 重写制作一个不和谐机器人,但最近遇到了一个问题.

I am making a discord bot using the discord.py rewrite and I have recently run into a problem.

我已发出加入用户语音频道的命令.问题是,当我在本地 PC 上运行它时,我的命令运行得非常好,但现在我试图在树莓派上运行它,它在连接到语音通道时失败.

I have made a command to join a user's voice channel. The thing is, my command works perfectly fine when I run it on my local PC, but now that I'm trying to run it on a raspberry pi it fails when connecting to the voice channel.

我已尝试安装所有依赖项,但无法正常工作.命令代码:

I have tried installing all dependencies but I just can't get it to work.Code for the command:

@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!")

没有引发异常.

推荐答案

您使用了错误的方式连接到语音通道.尝试使用此代码.

You are using a bad way to connect to the voice channel.Try using this code.

它识别用户的位置并在该语音通道中连接.

It identify where the user is and connect in that voice 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")

这篇关于Bot 无法连接到语音通道 - discord.py 重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:14