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

Viewed 19

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.

1 Answers

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
Related