Reputation: 84
I want to code a timed ban or mute, but with that I can restart my bot. Is there a nice libary or anyone has an idea to code it?
Thank you very much!
I code with discordpy cogs
Upvotes: 1
Views: 119
Reputation: 9
If it involves restarting your bot, then you cannot use your RAM to store your data but you need to use your Hard Disk for that. When your bot is running, it is storing its data inside the RAM and that's why you can re-use them while the bot is online. Once it goes offline or gets restarted, all the data are removed from the RAM because the program is shut down.
To store those data within the Hard Disk, you need a database. For such small projects, you can use JSON or SQLite. If the project scales, you can move to another SQL like MySQL that will handle a more complex and heavy database.
To make a bot that can do a timed message:
8/7/2021 6:19 PM
as a piece of data of when the bot is going to send the message.From a technical standpoint, you can use Discordpy for all the Discord stuff, datetime to check the time, JSON (or SQlite3) for the database.
Upvotes: 0
Reputation: 2907
You would have to use a database system such as MongoDB or MySQL. You will have to store the active timed ban/mute in a record/document or another table/collection. Then if you are using MySQL you would only select user's that are timed by using Tasks. In MongoDB, you just search for any users that are timed.
You would either make a separate cog or keep it in your moderation cog, it must be executed when it's ready and execute every 5-30 minutes checking if the time is older than the current time. You could use timestamps to accomplish this. Then just update the document/record once the time is up and remove their id from a ban list.
Upvotes: 1