'Problem when giving a role in status update
So I am facing a bit of a problem (mostly because I am new) I basically want to give a role to anyone who has "ziedd" in their status.
This is my code so far :
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [Discord.Intents.GUILDS, Discord.Intents.GUILD_PRESENCES, Discord.Intents.GUILD_MEMBERS]
});
client.on('presenceUpdate', async (oldPresence, newPresence) => {
const role = newPresence.guild.roles.cache.get("914891350875459614");
const member = newPresence.member
const activities = member.user.presence.activities[0];
if (activities && activities.state && (activities.state.includes( "ziedd" ) || activities.state.includes("ziedd" ))) {
return newPresence.member.roles.add(role)
.catch(err => {
console.log(err)
return;
})
}
else {
if(member.roles.cache.get(role.id)) {
newPresence.member.roles.remove(role)
}
}
})
client.login(process.env.TOKEN);
It doesn't want to start, I have this error in the console :
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
at Function.resolve (/home/runner/vanitycheck/node_modules/discord.js/src/util/BitField.js:152:11)
Can you please find a solution to my error and tell me what exactly to put on intents to make it give the role?
I am stuck, any idea/solution would be appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
