Trying to get a join / leave command working inside of a Cog. Getting the error "NameError: name 'client' is not defined" when using the command Join. I have tried to use 'self.client' instead but I just get an error that 'self' is not defined. Any help would be super appreciated. Thanks :)
import os
import youtube_dl
from discord.ext import commands
from discord.utils import get
class music(commands.Cog):
def __init__(self, bot):
self.bot = bot
#Events
#Commands
#Join Voice Chat
@commands.command(pass_context=True, aliases=['Join', 'JOIN'])
async def join(self, ctx):
channel = ctx.message.author.voice.channel
voice = get(self.client.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
await voice.disconnect()
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
print(f"Bot has connected to {channel}\n")
await ctx.send(f"Connected to {channel}")