I have a command that gives a user a role if they have .gg/ in their custom status. There are no error logs but the bot is not giving the role to the users who have this as their status.
client.on('presenceUpdate', async (oldPresence, newPresence) => {
const role = newPresence.guild.roles.cache.get('726517660279373986');
const member = newPresence.member;
const activities = member.user.presence.activities[0];
if (activities && (activities.state.includes('.gg/') || activities.state.includes('discord.gg/'))) {
return newPresence.member.roles.add(role);
}
else if (member.roles.cache.get(role.id)) {
newPresence.member.roles.remove(role);
}
});
Gateway Intents were introduced by Discord so bot developers can choose which events their bot receives based on which data it needs to function. Intents are named groups of pre-defined WebSocket events, which the discord.js client will receive.
You need the privileged GUILD_PRESENCE Intent to be enabled for setting up a functional presenceUpdate listener.
You may enable it by going to the Discord Developer Portal > Your Application > Bot > ( Scroll down and locate privileged intents ) > Turning on Presence intent.
This is what you'd be looking for:
