Skip to content

Check role that is added guildmemberupdate discordjs

On the event guildmemberupdate, I am trying to see if the event is in my server and if the role is a certain role. If all things are true, it will send a message. It does not send a message though

Here is the code

        this.on('guildMemberUpdate', function (guild, oldMember, newMember) {
            if( !== '#') {
            } else {
                const wc = new Discord.WebhookClient("#', 'lG-###-7RIXy3LIup80X");
                if (oldMember.roles.cache.size !== newMember.roles.cache.size) {
                    if (!oldMember.roles.cache.has("851156630748921927") && newMember.roles.cache.has("851156630748921927")) {
                        wc.send(`yo !`);

It doesn’t send ‘test’


The guildMemberUpdate event requires the server members intent. You can enable it in the Discord Developer Portal, and within your client instantiation

const { Intents } = require("discord.js")
const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS]})
//other intents may be added. Make sure it has server members intent (Intents.FLAGS.GUILD_MEMBERS)