Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Discord, Mention someone when gets a role

Is there a way to mention someone immediately after getting a specific role in a specific channel? For example when I, or any other admin, give someone a specific role the bot mentions them in a specific channel.

Here is my code:

client.on("guildMemberUpdate", (oldMember, newMember) => {
    const channel = client.channels.cache.get("channelid");

    // If the role(s) are present on the old member object but no longer on the new one (i.e role(s) were removed)
    const removedRoles = oldMember.roles.cache.filter((role) => !newMember.roles.cache.has("roleid"));
    if (removedRoles.size > 0) console.log(`The roles ${removedRoles.map((r) => r.name)} were removed from ${oldMember.displayName}.`);
    // If the role(s) are present on the new member object but are not on the old one (i.e role(s) were added)
    const addedRoles = newMember.roles.cache.filter((role) => !oldMember.roles.cache.has("roleid"));
    if (addedRoles.size > 0) {
        if (newMember.roles.cache.some((role) => role.name === "testing")) {
            let embed = new Discord.MessageEmbed().setTitle("♡﹕welcome!").setDescription("lalalala").setColor("#FFB6C1").setThumbnail("https://cdn.discordapp.com/attachments/806974794461216813/817737054745526304/giffy_2.gif");
            channel.send(`Welcome ${oldMember.user}`, embed);
        }
        console.log(`The roles ${addedRoles.map((r) => r.name)} were added to ${oldMember.displayName}.`);
    }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is assuming your code is exactly as shown in the question, and not using placeholder strings.

Firstly, "roleid" should be role.id without the "" when you're filtering. This will filter it properly, as should channelId where channel is defined, which I'm guessing are placeholders, but just in case.

Secondly, you'll probably want to check using addedRoles.has("roleIdToSend") as opposed to newMember.roles.cache.some(). This will DM them every time they're updated if they have the role, not if they only just got the role on that update.

Lastly, assuming you're using discord.js v13, you'll need to correct your send() method. It should look something like

channel.send({
  content: `Welcome, ${oldMember.toString()}`,
  embeds: [embed]
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!