モルシク2021-09-15 12:58:34
Node.js
モルシク, 2021-09-15 12:58:34

How to make the issuance of roles by reaction on discord.js?

I need the bot to create an embed message and add reactions to it, when clicked, certain roles are issued
. How should the code for issuing roles and adding reactions look like?
And is it worth adding a separate collection for such embed messages? (if so how)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Gusev, 2021-10-29
@Vadim_Dange

I hope I could help))
You create a message in your group and hang reactions on it, and then add the message ID to the code below, well, everything that is written there )

@bot.event # Добавить роль по реакции
async def on_raw_reaction_add(payload):
    if payload.message_id == 'ID сообщения - целое число, ковычки удалить' and payload.emoji.name == "Эмодзи рисунком - Пример: ":
        member = payload.member
        await member.add_roles(discord.utils.get(member.guild.roles, name='Название Роли или можете написать id = "И тут вписать без кавычек (name нужно заменить на id)"'))  # Добавление роли и и назначение


@bot.event # Удалить роль по реакции
async def on_raw_reaction_remove(payload):
    if payload.message_id == 'ID сообщения - целое число, ковычки удалить' and payload.emoji.name == "Эмодзи рисунком - Пример: ":
        guild = bot.get_guild(payload.guild_id)
        member = guild.get_member(payload.user_id)
        await member.remove_roles(discord.utils.get(member.guild.roles, name='Название Роли или можете написать id = "И тут вписать без кавычек(name нужно заменить на id)"'))  # Добавление роли и и назначение

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question