Skip to content
Advertisement

How to fix discord music bot attribute

Error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: ‘VoiceState’ object has no attribute ‘voice_channel’

Code:

from discord.ext import commands
import random
import youtube_dl

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

Advertisement

Answer

Try using voice.channel instead of voice.voice_channel.

from discord.ext import commands
import random
import youtube_dl

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

Also client.join_voice_channel will not work. Use something like this:

from discord.ext import commands
from discord.utils import get
import random
import youtube_dl
    
@client.command(pass_context=True)
async def join(ctx):
    chn = ctx.message.author.voice.channel
    if not chn:
        await ctx.send("Error: Connect to voice channel")
        return
    voice = get(bot.voice_clients, guild=ctx.guild)
    if voice and voice.is_connected():
        await voice.move_to(chn)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement