Skip to content

Commit

Permalink
sync roles once per day and fix the assign roles command to remove ro…
Browse files Browse the repository at this point in the history
…les correctly
  • Loading branch information
vFlyingCowboy committed Mar 23, 2024
1 parent 5a9a938 commit 967138f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion assign_roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function assignRoles(member) {
member.roles.add(discordRole).catch(e => console.log(e));
}
} else {
if (member.roles.cache.some(r => r.name === role)) {
if (member.roles.cache.some(r => r.name !== role)) {
member.roles.remove(discordRole).catch(e => console.log(e));
}
}
Expand Down
24 changes: 11 additions & 13 deletions events/ready.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
const {assignRoles} = require("../assign_roles.js");
const { ActivityType } = require('discord.js');
const {ActivityType} = require('discord.js');
const cron = require('node-cron')
module.exports = {
name: 'ready',
once: true,
async execute(client) {
console.log(`Logged in as ${client.user.tag}`);
client.user.setActivity('The VATSIM Network', { type: ActivityType.Watching })
setInterval(async function() {
const guild = client.guilds.cache.get("901078003482783765");
const members = await guild.members.fetch();
members.forEach(member =>
setInterval(function (){
assignRoles(member)
},500)
)
console.log("I have assigned everyone's roles");
},2*12*60*60*1000)
},
client.user.setActivity('The VATSIM Network', {type: ActivityType.Watching})
cron.schedule('30 02 * * *', async () => {
const guild = client.guilds.cache.get("901078003482783765");
const members = await guild.members.fetch();
members.forEach(member =>
assignRoles(member)
)
})
}
};
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"discord.js": "^14.11.0",
"dotenv": "^16.0.3",
"node-cron": "^3.0.3",
"nodemon": "^2.0.20",
"p-limit": "^3.1.0"
},
Expand Down

0 comments on commit 967138f

Please sign in to comment.