1

I'm starting in Python, I'm making a Discord bot few weeks, nowdays, when I was trying to make a "Poll System" in my bot, I had an error like this:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'author'

My code:

    @client.command()
async def hlasovani(self, ctx, volba1, volba2, *, tema):
    embed = discord.Embed(title = tema,description = f":one: {volba1}\n\n:two: {volba2}",color = ctx.author.color,timestamp = datetime.datetime.utcnow())
    embed.set_footer(text = f"Hlasování zahájil {ctx.author.name}")
    embed.set_thumbnail(url = ctx.author.avatar_url)
    message = await ctx.send(embed = embed)
    await message.add_reaction("1️⃣")
    await message.add_reaction("2️⃣")
    await asyncio.sleep(5)

    newmessage = await ctx.fetch_message(message.id)
    onechoice = await newmessage.reactions[0].users().flatten()
    secchoice = await newmessage.reactions[1].users().flatten()

    vysledek = "REMÍZA!"
    if len(onechoice)>len(secchoice):
        vysledek = volba1
    elif len(secchoice)<len(onechoice):
        vysledek = volba2

    embed = discord.Embed(title = tema, description = f"Výsledek: {vysledek}", color = ctx.author.color, timestamp = datetime.datetime.utcnow())
    embed.set_footer(text = f"{volba1} || {volba2}")

    await newmessage.edit(embed = embed)

I will be really thankful for any kind of help...

1
  • and what line does this error occur in, show full traceback (edit the post to include it) Commented Oct 20, 2021 at 16:13

1 Answer 1

1

Since you are using @client.command() instead of @commands.command(), I would assume your command is not in a cog or another class. If that's the case, you need to remove the self argument from your command.

async def hlasovani(ctx, volba1, volba2, *, tema):
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.