E
E
EcoTry2021-09-06 18:43:14
Python
EcoTry, 2021-09-06 18:43:14

I get an error TypeError: on_raw_reaction_add() missing 1 required positional argument: 'payload', what should I do?

@bot.event
async def on_raw_reaction_add(self, payload):
    if payload.message_id == config.POST_ID:
        channel = self.get_channel(payload.channel_id)  # получаем объект канала
        message = await channel.fetch_message(payload.message_id)  # получаем объект сообщения
        member = utils.get(message.guild.members,
                           id=payload.user_id)  # получаем объект пользователя который поставил реакцию

        try:
            emoji = str(payload.emoji)  # эмоджик который выбрал юзер
            role = utils.get(message.guild.roles, id=config.ROLES[emoji])  # объект выбранной роли (если есть)

            if (len([i for i in member.roles if i.id not in config.EXCROLES]) <= config.MAX_ROLES_PER_USER):
                await member.add_roles(role)
                print('[SUCCESS] User {0.display_name} has been granted with role {1.name}'.format(member, role))
            else:
                await message.remove_reaction(payload.emoji, member)
                print('[ERROR] Too many roles for user {0.display_name}'.format(member))

        except KeyError as e:
            print('[ERROR] KeyError, no role found for ' + emoji)
        except Exception as e:
            print(repr(e))

@bot.event
async def on_raw_reaction_remove(self, payload):
    channel = self.get_channel(payload.channel_id)  # получаем объект канала
    message = await channel.fetch_message(payload.message_id)  # получаем объект сообщения
    member = utils.get(message.guild.members,
                       id=payload.user_id)  # получаем объект пользователя который поставил реакцию


Mistake
gnoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Users\EXT\PycharmProjects\DiscordBotForDenis\venv\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_raw_reaction_add() missing 1 required positional argument: 'payload'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-09-06
@phaggi

Looked more attentively - on_raw_reaction_add accepts ONLY ONE ARGUMENT - payload. It's written in the documentation. And you have 2 arguments - self and payload.
The Discord API simply calls it with one payload argument, which falls into self, and does not actually receive the second argument. I think so.
What to do... maybe rewrite without self, as a function... I don't know, there is little data and little experience in these bots of yours.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question