0
@bot.command()
async def vote(reaction, ctx) :
    vote = ctx.message.content[4:].split(" / ")
    await ctx.send(ctx.channel, "[Vote] - " + vote[0])
    for i in range(1, len(vote)) :
        choose = await ctx.send(ctx.channel, "```" + vote[i] + "```")
        await ctx.add_reaction(choose, "⭕")
        await ctx.add_reaction(choose, "❌")

I get error :

Command raised an exception: AttributeError: 'str' object has no attribute 'message'

The following error appears when I execute the code.

It was executed before I entered these codes.

Finally, the add_reaction feature will not run in the discord.

How can I fix the error?

0

1 Answer 1

3

There are multiple errors in your code:

  • ctx must be the first argument of any command. In your case, the discord.Context object that you expect would be reaction and that's why you have this error. Your function definition should be:
    @bot.command()
    async def vote(ctx, reaction):
    
  • In the code you gave, the reaction variable is useless, if you shared your entire function, you can delete it.
  • The way you send messages is wrong, what you should do instead is this:
    await ctx.send(f"[Vote] - {vote[0]}")
    (...)
    msg = await ctx.send(f"```{vote[i]}```")
    
  • The way you add reaction is also wrong. What you have to do now is this:
    @bot.command()
    async def vote(ctx) :
        vote = ctx.message.content[4:].split(" / ")
        await ctx.send(ctx.channel, "[Vote] - " + vote[0])
        for i in range(1, len(vote)):
            msg = await ctx.send(f"```{vote[i]}```")
            await msg.add_reaction("⭕")
            await msg.add_reaction("❌")
    

It seems that you mix up the old discord.py (below v1.0) and the actual discord.py rewrite (after v1.0). The following link summarizes the difference between those two versions: Migrating to v1.0.

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

1 Comment

The error has been resolved! Thank you for your reply.

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.