So I have this code that was supposed to make a bot I created assign roles to members of my server after they’ve been in it for a certain period of time and announce when they had achieved getting each role. But it keeps giving me errors with the Intents. I made sure the perms for the bot matched the intents but still no luck.
const { Client, Intents } = require("discord.js");
const {token, guildId} = require("./config.json");
const {DateTime} = require("luxon");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS],
token: '[REDACTED]'
});
const roles = [
["Newcomer", 0],
["Apprentice Trainer", 7],
["Regular Trainer", 14],
["Advanced Trainer", 30],
["Experienced Trainer", 60],
["Proficient Trainer", 90],
["Veteran Trainer", 180],
["Expert Trainer", 270],
["Master Trainer", 365],
["Elite Trainer", 540],
["Champion Trainer", 730],
["Legendary Trainer", 1095],
["Grandmaster Trainer", 1460]
];
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag} - PokeProgressor`);
checkRolesLoop.start();
});
async function checkRoles() {
const guild = await client.guilds.fetch(1243576389324767383);
const rankUpChannel = guild.channels.cache.find(channel => channel.name === "rank-up");
if (!rankUpChannel) {
console.log("Rank-up channel not found. Please create a channel named 'rank-up");
return;
}
guild.members.cache.forEach(async member => {
const joinDate = member.joinedAt;
const daysInServer = DateTime.utc().diff(DateTime.fromJSDate(JoinDate), "days").days;
for (const [roleName, daysRequired] of roles.reverse()) {
const role = guild.roles.cache.find(role => role.name === roleName);
if (!role) continue;
if (daysInServer >= daysRequired && !member.roles.cache.has(role.id)){
await member.roles.add(role);
switch (roleName){
case "Champion Trainer":
await rankUpChannel.send(`🏅 ${member} has ascended to the rank of **${roleName}**! You're among the best of the best!`);
break;
case "Legendary Trainer":
await rankUpChannel.send(`🌟 ${member} has reached the prestigious rank of **${roleName}**! Your legend continues to grow!`);
break;
case "Grandmaster Trainer":
await rankUpChannel.send(`👑 ${member} has achieved the highest honor as **${roleName}**! Congratulations on becoming a true Pokémon Master!`);
break;
default:
await rankUpChannel.send(`🎉 ${member} has reached the rank of **${roleName}**! Keep progressing and aim for the top!`);
}
break;
}
}
});
}
setInterval(checkRoles, 24 * 60 * 60 * 1000); // Run every 24 hours
checkRoles();
client.login(token);