Send a message if there is a role Discord.js

Andryxa

Bot send a message if the User who clicked the reaction has the ROLE "ID"

I decided to try this, but it didn't work out

if(message.member.roles.cache.has(role.id)) {
  console.log(`Yay, the author of the message has the role!`);
} else {
  console.log(`Nope, noppers, nadda.`);
}

====Here is the main Code====

       sentMessage.react("✅");
        message.delete({ timeout: 100 });
        const filter = (reaction, user) => {
          return !user.bot && ["✅"].includes(reaction.emoji.name);
        };

        sentMessage
          .awaitReactions(filter, {
            max: 1,
            time: 60000,
          })
          .then((collected) => {
            const reaction = collected.first();

            if (reaction.emoji.name === "✅") {
              const member = reaction.users.cache.find((user) => !user.bot);
              
              message.author.send(Hello)
Zsolt Meszaros

You should check the role of the member who reacted (the member found in reaction.users.cache). reaction.users.cache returns a user, and you need a guild member to get their roles. You can use message.guild.members.fetch() or message.guild.member() for this. Now you can check if the returned member has the role:

sentMessage.awaitReactions(filter, {
  max: 1,
  time: 60000,
})
.then(async (collected) => {
  const reaction = collected.first();

  if (reaction.emoji.name === '1️⃣') {
    // find the first user who reacted and is not a bot
    const userReacted = reaction.users.cache.find((user) => !user.bot);
    // get the guild member
    const member = await message.guild.member(userReacted);

    if (!member.roles.cache.has('ROLE_ID')) return;

    message.author.send({
      embed: {
        color: 3447003,
        title: 'Вызов принят',
        description: `**Сотрудник:** ${member}`,
        timestamp: new Date(),
      },
    });
  }
})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to send message with discord.js with ID

From Dev

Discord.JS Send message to tagged user

From Dev

Discord.js -- make presenceUpdate send a message

From Dev

How do I send a message to a specific channel in discord.js?

From Dev

Check if a user can send message in a specific channel discord.js

From Dev

message.channel.send not working discord.js

From Dev

How to make discord bot wait for reply for 5 minutes and then send a message? Using discord js

From Dev

Add a role in Discord.js

From Dev

Discord.js bot error, console: DiscordAPIError: Cannot send an empty message

From Dev

How do I send a message without using the deprecated way "sendMessage" in discord.js?

From Dev

Python, capture OS output and send as a message in discord

From Dev

How to send a message to a different server | Discord Bot

From Dev

Finding all members with a role in Discord.js

From Java

Assign discord role when user reacts to message in certain channel

From Dev

JS send message on correct input

From Dev

JS send message on correct input

From Dev

Using SignalR to send message to client from Azure Worker Role

From Dev

Welcome message embed Discord.js

From Dev

Discord js using message id in Embed

From Dev

Discord.js How to mention message author?

From Dev

Await reply in private message discord.js

From Dev

Discord.py, there is any method do edit a message send by a webhook?

From Dev

Discord.py - Send message under different name or user

From Dev

Use Discord API to send a private message given a user ID

From Dev

Sending a message when prefix was send discord.py

From Dev

(discord.py) How to send content of a text file as a message

From Dev

discord py - Send a different message if a user replies to my bot

From Dev

Discord bot won't send my message to server but prints it in terminal

From Dev

NodeJS discord bot commands getting error Cannot send an empty message

Related Related

  1. 1

    How to send message with discord.js with ID

  2. 2

    Discord.JS Send message to tagged user

  3. 3

    Discord.js -- make presenceUpdate send a message

  4. 4

    How do I send a message to a specific channel in discord.js?

  5. 5

    Check if a user can send message in a specific channel discord.js

  6. 6

    message.channel.send not working discord.js

  7. 7

    How to make discord bot wait for reply for 5 minutes and then send a message? Using discord js

  8. 8

    Add a role in Discord.js

  9. 9

    Discord.js bot error, console: DiscordAPIError: Cannot send an empty message

  10. 10

    How do I send a message without using the deprecated way "sendMessage" in discord.js?

  11. 11

    Python, capture OS output and send as a message in discord

  12. 12

    How to send a message to a different server | Discord Bot

  13. 13

    Finding all members with a role in Discord.js

  14. 14

    Assign discord role when user reacts to message in certain channel

  15. 15

    JS send message on correct input

  16. 16

    JS send message on correct input

  17. 17

    Using SignalR to send message to client from Azure Worker Role

  18. 18

    Welcome message embed Discord.js

  19. 19

    Discord js using message id in Embed

  20. 20

    Discord.js How to mention message author?

  21. 21

    Await reply in private message discord.js

  22. 22

    Discord.py, there is any method do edit a message send by a webhook?

  23. 23

    Discord.py - Send message under different name or user

  24. 24

    Use Discord API to send a private message given a user ID

  25. 25

    Sending a message when prefix was send discord.py

  26. 26

    (discord.py) How to send content of a text file as a message

  27. 27

    discord py - Send a different message if a user replies to my bot

  28. 28

    Discord bot won't send my message to server but prints it in terminal

  29. 29

    NodeJS discord bot commands getting error Cannot send an empty message

HotTag

Archive