0
votes

I'm interested in making a discord bot using python. Im trying to make a bot that could join voice channel. This is my code, I already ran it but it's not working. I already did some research on the internet, but I think this code is completely fine?

   #Join Command
     @client.command()
     async def join(ctx):
         if(ctx.author.voice): #If in voice channel
            channel = ctx.author.voice.channel
            await channel.connect()
    
        else: #If not in voice channel
            await ctx.send("You must be in voice channel first !")

So have any idea why my code won't work? This is my first time using python btw.

1

1 Answers

0
votes
@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")

this is how we can join a discord bot to a voice channel.

destination is where the person already connected and want to add bot to that channel.