Discord Bot won't tell someone to join a voice channel, instead it just throws an error. Other parts work totally fine

If the User is not in a voice channel, Voice will be None, and thus will have no attribute "voice".

Try:

voice_channel = ctx.message.author.voice.channel if ctx.message.author.voice else None

https://discordpy.readthedocs.io/en/stable/api.html#discord.VoiceState


You need to use try: like so:

@commands.command(name="play", help="Plays a selected song from youtube")
    async def p(self, ctx, *args):
        query = " ".join(args)
        try:
            voice_channel = ctx.message.author.voice.channel
            song = self.search_yt(query)
            if type(song) == type(True):
                await ctx.send("Could not download the song. Incorrect format try another keyword. This could be due to playlist or a livestream format.")
            else:
                await ctx.send("Song added to the queue")
                self.music_queue.append([song, voice_channel])
        except:
            await message.channel.send("Connect to a voice channel!")