Report this

What is the reason for this report?

The problem of assigning a role using a reaction discord.js

Posted on February 2, 2022

I have a problem with assigning a role after clicking the appropriate response.

When the user responds to the message, no role is assigned and no message or error pops up in the console.

At this point, the role is not added, but a message pops up for the saved “Error adding role”. UPDATE:

client.on(“messageReactionAdd”, ({ message: { channel } }, user) => { if (/weryfikacja/.test(channel.name)) { channel.guild.members .fetch(user) .then(member => { member.roles .add(‘930796894026883153’) .then(() => { console.log( The ${roleName} has been removed from member ${user.tag} successfully! ); }) .catch(e => console.error(“Error adding role”)); }) .catch(error => { console.error(error); }); } });



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

If a role is not being assigned, and you aren’t seeing any errors in the console, there are a few potential issues to look at. Here are a couple of possibilities:

  • Privilege Hierarchy: Make sure the bot role is higher in the server settings than the role it’s trying to assign.
  • Permission Levels: Your bot might not have the necessary permissions to manage roles. Make sure it has the “Manage Roles” permission.
  • Correct Role ID: Ensure that you are using the correct Role ID

In your case, make sure that channel.name indeed contains the string ‘weryfikacja’, otherwise the function won’t execute. Also, consider adding console.log() statements at various points in your code for a better understanding of where the function fails.

If you are still having issues, ensure that you have the necessary node and discord.js versions. Check if promises are working correctly, especially since some libraries return promises that should eventually resolve or reject.

For additional assistance, check out this How To Build a Discord Bot with Node.js on DigitalOcean tutorial.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.