discord.py how to run command only if some reaction added

0

Issue

I’m trying to make like a shop command, It’s looks like this:
https://i.postimg.cc/2jcJT3r6/so.jpg
So i need to make like:
If ctx.author clicked on :island: reaction, buy the island.

Solution

You can use wait_for function:

@bot.command()
async def shop(ctx):
    message = await ctx.send("Test shop message")  # send a message
    emojis = ("🏝️", "2️⃣", "3️⃣")
    for emoji in emojis:  # add reactions with all emojis
        await message.add_reaction(emoji)
    check = lambda payload: payload.message_id == message.id and payload.channel_id == ctx.channel.id and str(payload.emoji) in emojis
    payload = await bot.wait_for('raw_reaction_add', check=check, timeout=100)  # wait for user choose one of available items
    if str(payload.emoji) == "🏝️":
        pass  # buy the island
    elif str(payload.emoji) == "2️⃣":
        pass  # buy the chest level 2
    elif str(payload.emoji) == "3️⃣":
        pass  # buy the chest level 3

Answered By – Ratery

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More