adabugra
adabugra
DIdiscord.js - Imagine ❄
Created by adabugra on 12/25/2023 in #djs-questions
Weird roles issue
const { Events } = require('discord.js');

module.exports = {
name: Events.GuildMemberUpdate,
async execute(oldMember, newMember) {
try {
// Fetch the full member from the guild
const guild = newMember.guild;

// Check if the member's roles have been updated
if (oldMember.roles.cache.size !== newMember.roles.cache.size) {
const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));

// Check if the added roles include the role to be removed
if (addedRoles.has('1188850631734206484')) {
// Remove the specified role
newMember.roles.remove('1150002502956236853')
.then(() => console.log(`Removed role 1150002502956236853 from ${newMember.user.tag}`))
.catch(error => console.error(`Error removing role: ${error.message}`));
}
}
} catch (error) {
console.error(`Error fetching member: ${error.message}`);
}
},
};
const { Events } = require('discord.js');

module.exports = {
name: Events.GuildMemberUpdate,
async execute(oldMember, newMember) {
try {
// Fetch the full member from the guild
const guild = newMember.guild;

// Check if the member's roles have been updated
if (oldMember.roles.cache.size !== newMember.roles.cache.size) {
const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));

// Check if the added roles include the role to be removed
if (addedRoles.has('1188850631734206484')) {
// Remove the specified role
newMember.roles.remove('1150002502956236853')
.then(() => console.log(`Removed role 1150002502956236853 from ${newMember.user.tag}`))
.catch(error => console.error(`Error removing role: ${error.message}`));
}
}
} catch (error) {
console.error(`Error fetching member: ${error.message}`);
}
},
};
is this correct
4 replies
DIdiscord.js - Imagine ❄
Created by adabugra on 12/25/2023 in #djs-questions
Weird roles issue
i have theese three intents -> GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent,
4 replies