0

this is the error I've recieved when I tried to use /play (/pusti on my lang) command on Discord in order to play a song from YT:

2023-12-01 21:25:11 ERROR discord.ext.commands.bot Ignoring exception in command pusti Traceback (most recent call last): File "C:\Users\x\AppData\Roaming\Python\Python312\site-packages\discord\ext\commands\core.py", line 235, in wrapped ret = await coro(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\discord-bot\main.py", line 149, in pusti voice_channel = ctx.author.voice.channel ^^^^^^^^^^ AttributeError: 'str' object has no attribute 'author'

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

Traceback (most recent call last): File "C:\Users\x\AppData\Roaming\Python\Python312\site-packages\discord\ext\commands\bot.py", line 1350, in invoke await ctx.command.invoke(ctx) File "C:\Users\x\AppData\Roaming\Python\Python312\site-packages\discord\ext\commands\core.py", line 1029, in invoke await injected(*ctx.args, **ctx.kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\x\AppData\Roaming\Python\Python312\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: 'str' object has no attribute 'author'

And this is the command I try to use on Discord:

@client.command(name = "pusti", aliases = ["p", "play", "playing"], help = "Pušta pesmu sa tvog linka. 🎵")    
    async def pusti(self, ctx, *args):
        query = " ".join(args)
        voice_channel = ctx.author.voice.channel
        if voice_channel is None:
            await ctx.send("➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖\nUđi prvo na neki voice kanal! 🎵\n➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖")
        elif self.is_paused:
            self.vc.resume()
        else:
            song = self.search_yt(query)
            if type(song) == type(True):
                await ctx.send("➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖\nTvoja pesma je sada u redu za čekanje. 🎵\n➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖")
                self.music_queue.append([song, voice_channel])
                if self.is_playing == False:
                    await self.play_music(ctx)

I've done everything the same as it is in course video, but somehow mine stuff does not work. Please help someone!

1 Answer 1

1

The problem seems to be that the function pusti does not receive the argument ctx correctly as the error clearly states:

AttributeError: 'str' object has no attribute 'author' Meaning ctx is passed as a string, which is probably (and this is me just assuming) because your function is not inside of a class, meaning that you don't need the parameter self. And the @client.command decorator passes the context and arguments meaning self will be the context and ctx will be the arguments. This is likely not what you want.

Because of that changing the function definition to async def pusti(ctx, *args) will do the trick, if my assumptions are correct.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.