Search code examples
pythondiscorddiscord.py

In discord.py voice.channel.connect() command doesn't work


So, after updating my version of discord.py my bot stopped working. Seems like it stops after encountering this line of code await ctx.author.voice.channel.connect(). Below is a piece of code

@commands.command()
    async def play(self, ctx, *, song=None):
        playlist = False

        if song is None:
            return await ctx.send('You must include a song to play')

        if ctx.author.voice is None:
            await ctx.send("You are not connected to a voice channel!")
            return

        if ctx.voice_client is None:
            await ctx.author.voice.channel.connect(reconnect=True)
            print(ctx.author.voice.channel.id)

        if song[0:4] != "http" and song[0:3] != "www":
            print("seaking")
            await ctx.send('Searching for a song, it will probably take a few seconds')

            result = await self.search_song(1, song, get_url=True)

            if result is None:
                return await ctx.send("Sorry, I could not find the given song")

            song = result

        url = youtube_dl.YoutubeDL(self.ydl_opts).extract_info(song, download=False)

        """'If' below is for checking whether it`s playlist or not and if it is, it will store this information for later use"""
        if 'entries' in url:
            playlist = True

(I've tried downgrading version, but that changed nothing). I've tried reinstalling package and changing intents. But nothing seems to work. Thanks for help in advance


Solution

  • It's most likely that while updating discord.py, you forgot to include PyNaCl, which is required for voice. Try reinstalling discord.py with the [voice] suffix.

    pip install -U discord.py[voice]