#Daily role checks

52 messages · Page 1 of 1 (latest)

cinder monolith

Is there a way to set up a function or interval to check members in a specific role every day at x time? I want to pull data from a database and check if users still have a role, and additionally, check for new members in a role every day.

primal burrowBOT
  • 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!
stuck junco
cinder monolith

What is a cronjob?

cinder monolith

What is the difference between cron and node-cron?

steady pawn

Use croner, it’s far better

cinder monolith
stuck junco

Probably not much, but just personal preference

cinder monolith

How would cron be most-effective in a role check? Would it be better to initialize it on the ready event?

stuck junco
cinder monolith

Okay, yeah

steady pawn

const { Cron } = require('croner')

Cron('0 0 * * *', () => {})

stuck junco
cinder monolith

Yeah, I'm not too hard on performance

I just want it to do the check every 12-24h or so

stuck junco

Yeah, will get the job done then

cinder monolith

How hard on the Discord API/ratelimits would it be to check the roles every 30m-1h or so

stuck junco
stuck junco
cinder monolith

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

steady pawn

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

stuck junco
cinder monolith
cinder monolith
steady pawn

Is this for a big bot or small

cinder monolith

For now, it is a small bot

stuck junco

<RoleManager>.cache would be your best bet then

stuck junco
cinder monolith

handling around 50-75 members at the moment

gotchaaaa

okay cool

so any cache check wouldn't hit the API?

steady pawn

I mean checking cache doesn’t make any api requests

stuck junco
cinder monolith

lovely

cinder monolith

@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

stuck junco
cinder monolith

See, but crontab says only 5 variables

stuck junco

That is correct

cinder monolith

and cronjob takes 6, which includes the job to the second

stuck junco

Are you sure, should only take 5

cinder monolith

I guess since it's v3, v3 takes 6

stuck junco