Bot can't connect to voice channel - discord.py rewrite


Question


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

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

There are no exceptions raised.


Answer 1:


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


来源:https://stackoverflow.com/questions/63449645/bot-cant-connect-to-voice-channel-discord-py-rewrite


码神部落- 版权声明 1、本主题所有言论和图片纯属会员个人意见,与码神部落立场无关。
2、本站所有主题由该帖子作者发表,该帖子作者屌丝范儿码神部落享有帖子相关版权。
3、码神部落管理员和版主有权不事先通知发贴者而删除本文。
4、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者屌丝范儿码神部落的同意。
5、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任。
6、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责。
7、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意。

最新回复 (0)
    • 码神部落
      2
        立即登录 立即注册 GitHub登录
返回
发新帖
作者最近主题: