1
votes

It's my first time asking a question here, so I might mess up in some areas.

So I have an economy bot, and I wanted this command to have 3 reactions so the person could tell it what to do. Here, this is to collect money, upgrade income or upgrade maximum capacity of their "company".

After having read the API documentations, I first had 3 check functions to check each reaction, such as this one:

(stuff)
message = await ctx.send(embed=embed)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await message.add_reaction("3️⃣")

def check1(reaction, user):
    return user == ctx.message.author and str(reaction.emoji) == "1️⃣"

        try:
            reaction, user = await client.wait_for("reaction_add", timeout = 30.0, check = check1)
        except asyncio.TimeoutError:
            print("Timeout")
        else:
            (code to collect money)

But then I realised that it would check for these one by one, so you'd have to wait for the 1st one to timeout before it would check for the 2nd one. So after some thinking, I came up with this:

(stuff)
message = await ctx.send(embed=embed)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await message.add_reaction("3️⃣")

def check(reaction, user):
    return user == ctx.message.author and user != "Robofriend#7565" and str(reaction.emoji) == "1️⃣" or "2️⃣" or "3️⃣"

try:
    reaction, user = await client.wait_for("reaction_add", timeout = 30.0, check = check)
except asyncio.TimeoutError:
    print("Timeout")
else:
    if str(reaction.emoji) == "1️⃣":
        (code to collect money)

I was supprised to discover that this was already answered here in stack overflow in the same way that I did, but for some reason, mine has a problem. When I run the command, the check returns True instantly, because it checks for its own reaction... I know this because I checked by making it print the user on the check function.

Any help appreciated!

1

1 Answers

0
votes

Well I found the problem:

In the check function, to prevent the bot from checking its own reaction, it checks if user == ctx.message.author. The problem here is that I had set the message the bot send to "message" in order to add the reactions:

message = await ctx.send(embed=embed)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await message.add_reaction("3️⃣")

All I did was change "message" to something else in the code above, and everything worked fine.