Puk
Puk

Reputation: 11

on_reaction_add event error in discord.py

I can't understand why it says there two arguments when I gave one?

When I try to execute this code

@bot.event
async def on_reaction_add(reaction):
    fp = reaction.message.guild.name
    l = reaction.message
    if os.path.isfile(ph + fp + '-bug.txt'):
        f = open(ph + fp + '-bug.txt')
        u = open(ph + fp + '-mod.txt')
        lines1 = u.readlines()
        lines = f.readlines()
        if str(l.channel.id) == lines1[0]:
            if reaction.emoji == "✅":
                channel = bot.get_channel(int(lines[0]))
                await channel.send(l.content)
            elif reaction.emoji == "❌":
                await l.delete()

i get this error

Traceback (most recent call last):
  File "C:\Users\---\PycharmProjects\---\venv\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
TypeError: on_reaction_add() takes 1 positional argument but 2 were given```


Upvotes: 0

Views: 448

Answers (1)

GayCookie
GayCookie

Reputation: 121

The on_reaction_add event requires the arguments reaction and user.
More you can read on this page!

So in order to make that event work, you should use it like this:

@bot.event
async def on_reaction_add(reaction, user):
    print(reaction) # Prints information about the reaction that was given.
    print(user) # Prints information about the user that gave the reaction.

Also: on_reaction_add() takes 1 positional argument but 2 were given
means that is expected to receive two arguments, but your event is only able to receive one

Upvotes: 2

Related Questions