I am building a bot where the bot needs to connect to a voice channel, here is my code:
import discord
from discord.ext import commands
from discord.utils import get
b = commands.Bot(command_prefix=".")
@b.event
async def on_ready():
print("Bot is logged in")
@b.command(pass_context=True, aliases=['j'])
async def join(ctx):
channel = ctx.message.author.voice.channel
voice = get(b.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
await ctx.send("Moved to the voice channel")
elif #Check if the user is in the voice channel and the bot is not:
voice = await channel.connect()
await ctx.send("Connected to the voice channel")
elif #Check if the user is in the voice channel
await ctx.send("**Get in a voice channel**")
elif #Check if the bot is already in the channel
await ctx.send("**Already in the channel**")
b.run("stack overflow")
So there's a couple things I want to check before entering the voice channel, I figured out how to connect and to move from different voice channel but am stuck there, I'm new to python so if my code can be simplified any suggestions would be much appreciated.