2022-12-02 08:53:58 +00:00
|
|
|
const fs = require("fs");
|
2022-05-23 07:40:08 +00:00
|
|
|
|
2022-12-02 08:53:58 +00:00
|
|
|
const Discord = require("discord.js");
|
2021-10-08 23:58:57 +00:00
|
|
|
const client = new Discord.Client({
|
|
|
|
intents: [
|
2022-12-02 08:53:58 +00:00
|
|
|
Discord.GatewayIntentBits.Guilds,
|
|
|
|
Discord.GatewayIntentBits.GuildMembers,
|
|
|
|
Discord.GatewayIntentBits.GuildMessageReactions,
|
|
|
|
],
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
|
|
|
|
2022-12-02 08:53:58 +00:00
|
|
|
const config = require("./config.json");
|
2021-10-08 23:58:57 +00:00
|
|
|
client.config = config;
|
|
|
|
|
2022-12-02 08:53:58 +00:00
|
|
|
const synchronizeSlashCommands = require("discord-sync-commands");
|
2021-10-08 23:58:57 +00:00
|
|
|
|
|
|
|
// Init discord giveaways
|
2022-12-02 08:53:58 +00:00
|
|
|
const { GiveawaysManager } = require("discord-giveaways");
|
2021-10-08 23:58:57 +00:00
|
|
|
client.giveawaysManager = new GiveawaysManager(client, {
|
2022-12-02 08:53:58 +00:00
|
|
|
storage: "./giveaways.json",
|
|
|
|
default: {
|
|
|
|
botsCanWin: false,
|
|
|
|
embedColor: "#FF0000",
|
|
|
|
reaction: "🎉",
|
|
|
|
lastChance: {
|
|
|
|
enabled: true,
|
|
|
|
content: "⚠️ **LAST CHANCE TO ENTER !** ⚠️",
|
|
|
|
threshold: 10000,
|
|
|
|
embedColor: "#FF0000",
|
|
|
|
},
|
|
|
|
},
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
2022-12-02 08:53:58 +00:00
|
|
|
// We not have a client.giveaways property to manage our giveaways
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:53:58 +00:00
|
|
|
client.giveawaysManager.on(
|
|
|
|
"giveawayReactionAdded",
|
|
|
|
(giveaway, member, reaction) => {
|
|
|
|
console.log(
|
|
|
|
`${member.user.tag} entered giveaway #${giveaway.messageId} (${reaction.emoji.name})`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:53:58 +00:00
|
|
|
client.giveawaysManager.on(
|
|
|
|
"giveawayReactionRemoved",
|
|
|
|
(giveaway, member, reaction) => {
|
|
|
|
console.log(
|
|
|
|
`${member.user.tag} unreact to giveaway #${giveaway.messageId} (${reaction.emoji.name})`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2021-10-08 23:58:57 +00:00
|
|
|
|
|
|
|
client.giveawaysManager.on("giveawayEnded", (giveaway, winners) => {
|
2022-12-02 08:53:58 +00:00
|
|
|
console.log(
|
|
|
|
`Giveaway #${giveaway.messageId} ended! Winners: ${winners
|
|
|
|
.map((member) => member.user.username)
|
|
|
|
.join(", ")}`
|
|
|
|
);
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/* Load all commands */
|
|
|
|
client.commands = new Discord.Collection();
|
|
|
|
fs.readdir("./commands/", (_err, files) => {
|
2022-12-02 08:53:58 +00:00
|
|
|
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,
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
2022-12-02 08:53:58 +00:00
|
|
|
console.log(`👌 Command loaded: ${commandName}`);
|
|
|
|
});
|
|
|
|
synchronizeSlashCommands(
|
|
|
|
client,
|
|
|
|
client.commands.map((c) => ({
|
|
|
|
name: c.name,
|
|
|
|
description: c.description,
|
|
|
|
options: c.options,
|
|
|
|
type: Discord.ApplicationCommandType.ChatInput,
|
|
|
|
})),
|
|
|
|
{
|
|
|
|
debug: true,
|
|
|
|
}
|
|
|
|
);
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/* Load all events */
|
|
|
|
fs.readdir("./events/", (_err, files) => {
|
2022-12-02 08:53:58 +00:00
|
|
|
files.forEach((file) => {
|
|
|
|
if (!file.endsWith(".js")) return;
|
|
|
|
const event = require(`./events/${file}`);
|
|
|
|
let eventName = file.split(".")[0];
|
|
|
|
console.log(`👌 Event loaded: ${eventName}`);
|
|
|
|
client.on(eventName, event.bind(null, client));
|
|
|
|
delete require.cache[require.resolve(`./events/${file}`)];
|
|
|
|
});
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Login
|
|
|
|
client.login(config.token);
|