startet currency system, think i added temporary ban and a give command

This commit is contained in:
2025-03-12 19:35:49 +01:00
parent 8fd4ed237b
commit 329d3a131d
7 changed files with 194 additions and 15 deletions
+44
View File
@@ -0,0 +1,44 @@
const { Events } = require('discord.js');
const { connectToDatabase } = require('../db.js');
module.exports = {
name: Events.ClientReady,
async execute(client) {
const dbClient = await connectToDatabase();
const db = dbClient.db('discord');
const tempBanCollection = db.collection('tempban');
// 2) Define a function to schedule unbans
async function scheduleUnban(banData) {
const delay = banData.banTime - Date.now();
if (delay <= 0) {
return;
}
setTimeout(async () => {
try {
const guild = await client.guilds.fetch(banData.guildId);
await guild.bans.remove(banData.userId);
await tempBanCollection.deleteOne({ _id: banData._id });
} catch (err) {
console.error('Error unbanning member:', err);
}
}, delay);
}
try {
const allBans = await tempBanCollection.find({}).toArray();
allBans.forEach(scheduleUnban);
tempBanCollection.watch().on('change', (change) => {
if (change.operationType === 'insert') {
const newBan = change.fullDocument;
scheduleUnban(newBan);
}
});
} catch (err) {
console.error('Error setting up unban system:', err);
}
},
};