Edit a database when mute/warn is over
So, I did a command to mute (using timeout method, no problem, it works), same for warn (simple message).
For each and every sanction made by a moderator, it's stored in a SQLite database with some useful infos. Now i can have the infos stored in the db, and the message of "warn/mute executed".
What i'm stuck onto is how to make a long period timeout ? Say 3 months ? I tried, on ChatGPT recommandation (so like, worst idea I could have had but who knows) to use node-cron and 'events' so that an event is emitted, and another file receive it, and launch a cron.schedule to the said date, and then it executes the code of updating the db and sending a message saying the sanction is over.
(Files in next message)
2 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- 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!So far, I've tried this (emitter file):
And the receiver file :
So I just... don't know what's wrong, or what can I do. There is no error message. The database isn't changed neither, so I guess it just never receives the event ? Thank you for your help, if there is any easier way (if this is even a way)...
Discord.js is 14.12.1
Node.js is 18.13.0
But that would need to analyse the database at least every minute wouldn't it ? Which would be quite resourceful ?
(Unless I didn't understand what you meant, I'm quite new with javascript, and thus discord.js and node.js)
yes but the bigger interval the least precise the durations. If I do it every 5 minutes for example, first on at t0. I mute someone for 5min at t1. When the test happens at t5, there is still 1 minute to go. So it passes. But then, 1 min later... nothing, you need to wait t10 for the next message. Which, I mean, can be okay, but it would be best to have it precisely set...
But if you tell me there is no easy other way then nevermind I'll do it that way (thus a cronjob would be the easiest right ?)
oooh, true true. Is it async ? (I don't have the right word I think but like, if I have two that will end before the end can I make two setTimeout or do I need to make them in order from nearest to furthest ?)
okay perfect then, I will make that, thank you very much !
Okay I'm so sorry to bother you again, but I- I don't understand why that part doesn't work. Basically I try to access my database, well, to analyse it. Except it just... doesn't seem to know it's existence. What I don't understand is that it is used in my first warn/mute command and there is no problem at all, but here it just doesn't want to.
My code :
The error I get :
I declared Sanctions globally with
global.Sanctions = ...
but what I really don't understand is why would it work with my warn/mute command file but not this one ?
Oh ok, my bad 😅
Have a nice day, and sorry for the mistake ^^