Programming a Discord bot with Python- How do I make it join a voice channel?

Viewed 895

I want to make the bot join the voice channel that I'm in when prompted. Here's what I have:

@client.event
async def on_message(message):
  if message.content.startswith('.join'):
    channel = 775902254951301125
    await channel.connect()

It doesn't seem to work, any tips?

2 Answers

I think this is what you're looking for!

@client.command(pass_context=True)
async def join(ctx):
    channel = ctx.message.author.voice.voice_channel
    await client.join_voice_channel(channel)

That was pulled straight from this video which was just a google search away.

Related