Fixed some bugs - EmotionChild

Fixed some bugs which were causing errors
This commit is contained in:
EmotionChild 2021-12-13 13:25:45 +13:00
parent 732cc0c468
commit b4c4c7bd1e
4 changed files with 61 additions and 48 deletions

View file

@ -4,6 +4,7 @@ const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS
]
});
@ -13,71 +14,96 @@ client.config = config;
// Load quickmongo
const { Database } = require('quickmongo');
const db = new Database(`${config.mongo_url}`);
const db = new Database(config.mongodb_url);
// check the DB when it's ready
db.once('ready', async () => {
if (!Array.isArray(await db.get('giveaways')) === null) await db.set('giveaways', []);
// start the manager only if the db got checked to prevent an error
// Ceck the DB when it is ready
db.on('ready', async () => {
if (!Array.isArray(await b.get('giveaways'))) await db.set('giveaways', []);
// Start the manager only after the BD got checked to prevent an error
client.giveawaysManager._init();
console.log('SUCCESS!');
});
})
// Init discord giveaways
const { GiveawaysManager } = require('discord-giveaways');
class GiveawayManagerWithOwnDatabase extends GiveawaysManager {
// This funtion is called when the manager need to get all the giveaways stored in the database
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
// This function is called when the manager needs to get all giveaways which are stored in the database.
async getAllGiveaways() {
// Get all giveaways from the database
return await db.get('giveaways');
}
// This function is called when a giveaway needs to be saved in the database (when a giveaway is created or when a giveaway is edited).
async saveGiveaway(messageID, giveawayData) {
// Add the nw one
// This function is called when a giveaway needs to be saved in the database.
async sameGiveaway(messageId, giveawayData) {
// Add the giveaway to the database
await db.push('giveaways', giveawayData);
// Can't forget to return something.
// Don't forget to return something!
return true;
}
async editGiveaway(messageID, giveawayData) {
// Gets all the current giveaways
// This function is called when a giveaway needs to be edited in the database.
async editGiveaway(messageId, giveawayData) {
// Get all giveaways from the database
const giveaways = await db.get('giveaways');
// Remove the old giveaway from the current giveaways ID
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageID !== messageID);
// Push the new giveaway to the array
// Remove the unexisting giveaway from the array
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
// Push the edited giveaway to the array
newGiveawaysArray.push(giveawayData);
// Save the updated array
await db.set('giveaways', newGiveawaysArray);
// Can't forget to return something.
// Don't forget to return something!
return true;
}
async deleteGiveaway(messageID) {
// Gets all the current giveaways
const data = await db.get('giveaways');
// Remove the giveaway from the array
const newGiveawaysArray = data.filter((giveaway) => giveaway.messageID !== messageID);
// This function is called when a giveaway needs to be deleted from the database.
async deleteGiveaway(messageId) {
// Get all giveaways from the database
const giveaways = await db.get('giveaways');
// Remove the unexisting giveaway from the array
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
// Save the updated array
await db.set('giveaways', newGiveawaysArray);
// Can't forget to return something.
// Don't forget to return something!
return true;
}
}
};
// Create a new instance of your new class
const manager = new GiveawayManagerWithOwnDatabase(client, {
updateCountdownEvery: 10000,
default: {
botsCanWin: false,
embedColor: "#FF0000",
embedColor: '#FF0000',
embedColorEnd: '#000000',
reaction: "🎉"
reaction: '🎉',
}
}, false)
}, false);
client.giveawaysManager = manager;
/* Load all events */
/* Load all commands */
client.commands = new Discord.Collection();
fs.readdir("./commands/", (_err, files) => {
files.forEach((file) => {
if(!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
client.commands.set(commandName, {
name: commandName,
...props
});
console.log(`👌 Command loaded: ${commandName}`);
});
synchronizeSlashCommands(client, client.commands.map((c) => ({
name: c.name,
description: c.description,
options: c.options,
type: 'CHAT_INPUT'
})), {
debug: true
});
});
/* Load all commands */
fs.readdir("./events/", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
@ -85,20 +111,7 @@ fs.readdir("./events/", (_err, files) => {
let eventName = file.split(".")[0];
console.log(`👌 Event loaded: ${eventName}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
client.commands = new Discord.Collection();
/* Load all commands */
fs.readdir("./commands", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
client.commands.set(commandName, props);
console.log(`👌 Command loaded: ${commandName}`);
delete require.cache[require.resolve(`.events/${file}`)];
});
});

View file

@ -1,5 +1,6 @@
{
"token": "Discord Bot Token",
"mongo_url": "mongodb://localhost:27017/giveawaychild",
"everyoneMention": false,
"hostedBy": true
}

View file

@ -10,5 +10,4 @@ module.exports = (client, interaction) => {
});
command.run(client, interaction);
};

View file

@ -1,6 +1,6 @@
{
"name": "giveaway-child",
"version": "2.0.0",
"version": "2.0.1",
"description": "",
"main": "index.js",
"scripts": {
@ -24,7 +24,7 @@
"beautify": "^0.0.8",
"discord-giveaways": "^5.0.1",
"discord-sync-commands": "^0.3.0",
"discord.js": "^13.2.0",
"discord.js": "^13.3.1",
"fero-ms": "^2.0.7",
"ms": "^2.1.3",
"quickdb": "^1.0.5",