I looked all the questions about connecting discord bot to voice channel for playing sound purposes but I couldn't find the answer I need. I'm new to the discord library and didn't solve how things work so when I try given answers in site I mostly get errors like this:
AttributeError: 'NoneType' object has no attribute 'channel'
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'channel'
My code looks like this:
import discord
from dotenv import load_dotenv
from discord.ext import commands
load_dotenv()
token = "XXXXXXXXXXXXXXXXX"
client = commands.Bot(command_prefix='.')
voice = discord.VoiceChannel
@client.command(name="join")
async def join(ctx):
channel = ctx.author.voice.channel
voice = get(self.bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
client.run(Token)
This is just the voice part of the code other send or event parts are working.