Carter Michaelis
Carter Michaelis

Reputation: 275

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

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?

Upvotes: 3

Views: 2667

Answers (2)

tre flse
tre flse

Reputation: 1

import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '>')

@client.event
async def on_ready():
  print ("Log : "+str(client.user))
  ch = await client.fetch_channel("enter id voice channel")
  await ch.connect()


client.run('token')

Upvotes: 0

goose.mp4
goose.mp4

Reputation: 272

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.

Upvotes: 1

Related Questions