How to make a bot join voice channels discord.py

10,961

You're really close! The only thing you've got to change is:

@commands.command()
async def join_voice(self, ctx):
    connected = ctx.author.voice
    if connected:
        await connected.channel.connect() #  Use the channel instance you put into a variable

What you were doing was grabbing the VoiceChannel class object, and not the actual VoiceChannel instance that the user was connected to. That's where your error came in, as it was trying to find a voice channel which didn't exist.

Glad to see the progress, keep it up!

Share:
10,961
Legacy Coding
Author by

Legacy Coding

Hi, Im a fairly new programmer, and I also stream to twitch https://twitch.tv/danhowe0

Updated on June 09, 2022

Comments

  • Legacy Coding
    Legacy Coding about 2 years

    I'm using discord.py to create a music bot, but I'm having trouble connecting the bot to a voice channel. Im using a Cog to seperate the music features from the rest.

    @commands.command()
    async def join_voice(self, ctx):
        channel = ctx.author.voice.channel
        print(channel.id)
        await self.client.VoiceChannel.connect()
    

    But I get the error: AttributeError: 'NoneType' object has no attribute 'channel'

    I've looked all through the docs and all the similar questions on here and still no solutions!

    Could someone help please?