voice = await channel.connect() not working

47 Views Asked by At

My discord bot is not joining voice channels here is the code

@client.command(pass_context = True)
async def join(ctx):
    if(ctx.author.voice):
        channel = ctx.voice_client
        voice = await channel.connect()
        source = FFmpegPCMAudio('test.wav')
        player = voice.play(source)
   else:
        await ctx.send("Error: You are not in a voice channel.")

the error:

ERROR    discord.ext.commands.bot Ignoring exception in command join
Traceback (most recent call last):
  File "C:\Users\-----\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\-----\OneDrive\Desktop\Coding\Cosmic\main.py", line 37, in join
    voice = await channel.connect()
                  ^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'connect'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\-----\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\-----\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\-----\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\ext\commands\core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError:         'NoneType' object has no attribute 'connect'

I did pip install Pynacl and imported it

import discord
from discord.ext import commands
from discord import FFmpegPCMAudio
import nacl
0

There are 0 best solutions below