#Daily role checks
52 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
A Cronjob sounds like what you want
What is a cronjob?
What is the difference between cron and node-cron?
Use croner, it’s far better
Probably not much, but just personal preference
How would cron be most-effective in a role check? Would it be better to initialize it on the ready event?
You could start the cron job in your ready event, and then it will run at your schedule
Okay, yeah
const { Cron } = require('croner')
Cron('0 0 * * *', () => {})
It's not so much about being effective at the task at hand, it just executes code at a specific time, if that is what you were asking. In terms of performance, I have no clue lol
Yeah, I'm not too hard on performance
I just want it to do the check every 12-24h or so
Yeah, will get the job done then
How hard on the Discord API/ratelimits would it be to check the roles every 30m-1h or so
You can use https://crontab.guru/every-12-hours to help with syntax
I'm not too sure, best guess is the lesser the better though. If you can hold off and do it once a day, do that instead
gotchaa
It's more of an in-the-moment service request type of thing
Users purchase their subscription and want access asap
it'd be unrealistic to check every 5 minutes, because that's very hard on the API
I mean, as long as you have the GuildMembers intent for example, then member roles are cached. Roles are cached by default, the removing/adding will be the api heavy part
If you're just checking roles every so often, I think you can just check the cache, not really sure of your use case though
Yeah, I'm not modifying the roles, I'm just checking
Okay, so yeah, checking cache wouldn't be heavy then, I assume?
Is this for a big bot or small
For now, it is a small bot
<RoleManager>.cache would be your best bet then
You wont hit the API at all here
handling around 50-75 members at the moment
gotchaaaa
okay cool
so any cache check wouldn't hit the API?
I mean checking cache doesn’t make any api requests
Correct, it's all locally cached data
lovely
@stuck junco @steady pawn sorry lads, but
const job = new CronJob(
'* * 1 * * *', // cronTime
function () {
console.log("Cronjob running: " + new Date(this.nextDate()));
}, // onTick
null, // onComplete
true, // start
'America/Los_Angeles', // timeZone
null, // context
true // runOnInit
);```
Am I doing anything wrong?
I'd like it to run every hour
Updated:
const job = new CronJob(
'0 0 */1 * * *', // cronTime
function () {
console.log("Cronjob running: " + new Date(this.nextDate()));
}, // onTick
null, // onComplete
true, // start
'America/Los_Angeles', // timeZone
null, // context
true // runOnInit
);```
I believe the second one means, it runs on startup and then runs on the hour
All looks good except the expression, every hour would be 0 * * * * meaning "at the start of every hour" or "minute 0 past every hour"
See, but crontab says only 5 variables
That is correct
and cronjob takes 6, which includes the job to the second
Are you sure, should only take 5
I guess since it's v3, v3 takes 6
Yeah looks like it. In that case your expression here #1173027506668974180 message should be correct