K
K
Kir Mozor2022-02-06 10:01:03
Python
Kir Mozor, 2022-02-06 10:01:03

Why can't the bot enter the VoiceChannel?

Hello everyone, there is one problem. I am developing a music bot for Discord, I need the bot to enter the VoiceChannel, but the error is:

Traceback (most recent call last):
  File "/home/kirill/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/kirill/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/kirill/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'channel'

Here is the code:
import config
import discord
from discord.ext import commands
import yandex_music

#client = discord.Client(command_prefix = '!')
bot = commands.Bot(command_prefix=config.PREFIX)

@bot.command()
async def hi(ctx):
    author = ctx.message.author
    await ctx.send(f'sup, {author.mention}')
    
@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()

@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

@bot.command()
async def whoa(ctx):
    if ctx.message.content.startswith('!whoa'):
        channel = ctx.message.channel
        await ctx.channel.send(ctx.message.content[5:].format(ctx.message))


#client = commands.Bot(command_prefix='?', intents = discord.Intents.all())


bot.run(config.TOKEN)

What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kir Mozor, 2022-02-06
@150_Kirill_150

And so, I'm a boobie.
You need to go to the VoiceChannel yourself, and then give a command in order for the bot to enter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question