How a discord bot can join a voice channel in discord rewrite?

47,383

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.

It now would look like this:

@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.

Share:
47,383
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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)

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

    can someone help me?

  • Nom1fan
    Nom1fan almost 4 years
    await voice_channel.connect() just hangs for me and nothing happens. Any idea what I'm doing wrong?
  • Eight Rice
    Eight Rice over 3 years
    AttributeError: 'User' object has no attribute 'voice'.