Fixed some bugs - EmotionChild
Fixed some bugs which were causing errors
This commit is contained in:
parent
732cc0c468
commit
b4c4c7bd1e
4 changed files with 61 additions and 48 deletions
|
@ -4,6 +4,7 @@ const Discord = require('discord.js');
|
||||||
const client = new Discord.Client({
|
const client = new Discord.Client({
|
||||||
intents: [
|
intents: [
|
||||||
Discord.Intents.FLAGS.GUILDS,
|
Discord.Intents.FLAGS.GUILDS,
|
||||||
|
Discord.Intents.FLAGS.GUILD_MEMBERS,
|
||||||
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS
|
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -13,71 +14,96 @@ client.config = config;
|
||||||
|
|
||||||
// Load quickmongo
|
// Load quickmongo
|
||||||
const { Database } = require('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
|
// Ceck the DB when it is ready
|
||||||
db.once('ready', async () => {
|
db.on('ready', async () => {
|
||||||
if (!Array.isArray(await db.get('giveaways')) === null) await db.set('giveaways', []);
|
if (!Array.isArray(await b.get('giveaways'))) await db.set('giveaways', []);
|
||||||
// start the manager only if the db got checked to prevent an error
|
// Start the manager only after the BD got checked to prevent an error
|
||||||
client.giveawaysManager._init();
|
client.giveawaysManager._init();
|
||||||
console.log('SUCCESS!');
|
console.log('SUCCESS!');
|
||||||
});
|
})
|
||||||
|
|
||||||
// Init discord giveaways
|
// Init discord giveaways
|
||||||
const { GiveawaysManager } = require('discord-giveaways');
|
const { GiveawaysManager } = require('discord-giveaways');
|
||||||
class GiveawayManagerWithOwnDatabase extends GiveawaysManager {
|
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||||
// This funtion is called when the manager need to get all the giveaways stored in the database
|
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||||
async getAllGiveaways() {
|
async getAllGiveaways() {
|
||||||
|
// Get all giveaways from the database
|
||||||
return await db.get('giveaways');
|
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).
|
// This function is called when a giveaway needs to be saved in the database.
|
||||||
async saveGiveaway(messageID, giveawayData) {
|
async sameGiveaway(messageId, giveawayData) {
|
||||||
// Add the nw one
|
// Add the giveaway to the database
|
||||||
await db.push('giveaways', giveawayData);
|
await db.push('giveaways', giveawayData);
|
||||||
// Can't forget to return something.
|
// Don't forget to return something!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async editGiveaway(messageID, giveawayData) {
|
// This function is called when a giveaway needs to be edited in the database.
|
||||||
// Gets all the current giveaways
|
async editGiveaway(messageId, giveawayData) {
|
||||||
|
// Get all giveaways from the database
|
||||||
const giveaways = await db.get('giveaways');
|
const giveaways = await db.get('giveaways');
|
||||||
// Remove the old giveaway from the current giveaways ID
|
// Remove the unexisting giveaway from the array
|
||||||
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageID !== messageID);
|
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
|
||||||
// Push the new giveaway to the array
|
// Push the edited giveaway to the array
|
||||||
newGiveawaysArray.push(giveawayData);
|
newGiveawaysArray.push(giveawayData);
|
||||||
// Save the updated array
|
// Save the updated array
|
||||||
await db.set('giveaways', newGiveawaysArray);
|
await db.set('giveaways', newGiveawaysArray);
|
||||||
// Can't forget to return something.
|
// Don't forget to return something!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteGiveaway(messageID) {
|
// This function is called when a giveaway needs to be deleted from the database.
|
||||||
// Gets all the current giveaways
|
async deleteGiveaway(messageId) {
|
||||||
const data = await db.get('giveaways');
|
// Get all giveaways from the database
|
||||||
// Remove the giveaway from the array
|
const giveaways = await db.get('giveaways');
|
||||||
const newGiveawaysArray = data.filter((giveaway) => giveaway.messageID !== messageID);
|
// Remove the unexisting giveaway from the array
|
||||||
|
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
|
||||||
// Save the updated array
|
// Save the updated array
|
||||||
await db.set('giveaways', newGiveawaysArray);
|
await db.set('giveaways', newGiveawaysArray);
|
||||||
// Can't forget to return something.
|
// Don't forget to return something!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Create a new instance of your new class
|
// Create a new instance of your new class
|
||||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||||
updateCountdownEvery: 10000,
|
|
||||||
default: {
|
default: {
|
||||||
botsCanWin: false,
|
botsCanWin: false,
|
||||||
embedColor: "#FF0000",
|
embedColor: '#FF0000',
|
||||||
embedColorEnd: '#000000',
|
embedColorEnd: '#000000',
|
||||||
reaction: "🎉"
|
reaction: '🎉',
|
||||||
}
|
}
|
||||||
}, false)
|
}, false);
|
||||||
|
|
||||||
client.giveawaysManager = manager;
|
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) => {
|
fs.readdir("./events/", (_err, files) => {
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
if (!file.endsWith(".js")) return;
|
if (!file.endsWith(".js")) return;
|
||||||
|
@ -85,20 +111,7 @@ fs.readdir("./events/", (_err, files) => {
|
||||||
let eventName = file.split(".")[0];
|
let eventName = file.split(".")[0];
|
||||||
console.log(`👌 Event loaded: ${eventName}`);
|
console.log(`👌 Event loaded: ${eventName}`);
|
||||||
client.on(eventName, event.bind(null, client));
|
client.on(eventName, event.bind(null, client));
|
||||||
delete require.cache[require.resolve(`./events/${file}`)];
|
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}`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"token": "Discord Bot Token",
|
"token": "Discord Bot Token",
|
||||||
|
"mongo_url": "mongodb://localhost:27017/giveawaychild",
|
||||||
"everyoneMention": false,
|
"everyoneMention": false,
|
||||||
"hostedBy": true
|
"hostedBy": true
|
||||||
}
|
}
|
|
@ -10,5 +10,4 @@ module.exports = (client, interaction) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
command.run(client, interaction);
|
command.run(client, interaction);
|
||||||
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "giveaway-child",
|
"name": "giveaway-child",
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
"beautify": "^0.0.8",
|
"beautify": "^0.0.8",
|
||||||
"discord-giveaways": "^5.0.1",
|
"discord-giveaways": "^5.0.1",
|
||||||
"discord-sync-commands": "^0.3.0",
|
"discord-sync-commands": "^0.3.0",
|
||||||
"discord.js": "^13.2.0",
|
"discord.js": "^13.3.1",
|
||||||
"fero-ms": "^2.0.7",
|
"fero-ms": "^2.0.7",
|
||||||
"ms": "^2.1.3",
|
"ms": "^2.1.3",
|
||||||
"quickdb": "^1.0.5",
|
"quickdb": "^1.0.5",
|
||||||
|
|
Loading…
Reference in a new issue