0
votes

I'm new to discord bot making, and I'd like to have the bot add a reaction to my message that, once pressed, allows the user reacting to pick up a role. What would be the code to allow me to do this? Thank you.

1

1 Answers

0
votes

This is a very well written and formatted question! In order for the bot to detect that the reaction is on a specific message, you can do many ways. The easiest way would be to be by ID, so I'm just going to do this with a simple command.

messageIDs = []

@client.event
async def on_raw_reaction_add(payload):
    global messageIDs

    for messageID in messageIDs:
        if messageID == payload.message_id:
            user = payload.member
            role = "roleName"
            await user.add_roles(discord.utils.get(user.guild.roles, name = role))

@client.command()
async def addMessage(ctx, messageID):
    global messageIDs
    
    emoji = "👍"
    channel = ctx.message.channel

    try:
        msg = await channel.fetch_message(messageID)
    except:
        await ctx.send("Invalid Message ID!")
        return
    await msg.add_reaction(emoji)
    messageIDs.append(messageID)