0
votes

I've coded a discord bot that adds a role to a user who reacted to a message. The bot also replies to the message 'Hallo Bot'. But when I turn off the bot and turn it on again, the bot won't reply to the message before I reacted to the other message.

    async def on_raw_reaction_add(self, payload):
        mitglied = discord.utils.get(payload.member.guild.roles, name="Mitglied")
        if str(payload.emoji) == "????":
            await payload.member.add_roles(mitglied)

    async def on_message(self, message):
        if message.content.startswith("Hallo Bot"):
            await message.channel.send("Hallo " + str(message.author.name))
1

1 Answers

0
votes

Try this:

@client.event
async def on_reaction_add(reaction, user):
        mitglied = discord.utils.get(user.member.guild.roles, name="Mitglied")
        user_id = reaction.user.author.id
        user = client.get_user(user_id)
        if reaction == "👍":
            await user.add_roles(mitglied)
@client.event
async def on_message(message):
       if message.content.startswith("Hallo Bot"):
          await message.channel.send(f"Hallo <@{message.author.id}>")

Your code is being executed in one single event, and that should not be the case as message and reaction are 2 different events. I've separated them, now whenever you type "Hallo Bot" the bot should reply to you before you having to react to the message.