2022-03-26 03:33:18 -05:00
|
|
|
#!/usr/bin/env -S node
|
|
|
|
|
2021-02-11 21:39:01 -06:00
|
|
|
const fs = require('fs');
|
|
|
|
const Discord = require('discord.js');
|
2022-03-28 10:56:21 -05:00
|
|
|
const config = require('./config.json');
|
2022-04-21 18:09:21 -05:00
|
|
|
console.log('Starting!');
|
|
|
|
const client = new Discord.Client({ intents: config.intents.map(intent => eval(`Discord.Intents.FLAGS.${intent}`)) });
|
2021-02-11 21:39:01 -06:00
|
|
|
|
2022-04-21 20:53:03 -05:00
|
|
|
client.commands = new Discord.Collection();
|
|
|
|
fs.readdirSync('./commands').filter(file => file.endsWith('.js')).forEach(file => {
|
2022-04-21 18:09:21 -05:00
|
|
|
const command = require(`./commands/${file}`);
|
|
|
|
client.commands.set(command.name, command);
|
2022-04-21 20:53:03 -05:00
|
|
|
});
|
2021-02-11 21:39:01 -06:00
|
|
|
|
2022-04-21 18:09:21 -05:00
|
|
|
client.generateErrorMessage = (errorMsg, avatarURL) => ({
|
|
|
|
embeds: [{
|
|
|
|
title: '<:AnitroxError:809651936563429416> Error',
|
|
|
|
color: 13632027,
|
|
|
|
footer: {
|
|
|
|
icon_url: avatarURL,
|
|
|
|
text: config.footerTxt
|
|
|
|
},
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'Something went wrong!',
|
|
|
|
value: errorMsg
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
});
|
2022-03-26 12:31:03 -05:00
|
|
|
|
2022-04-21 18:09:21 -05:00
|
|
|
client.on('error', (e) => console.log(`[ERROR] ${e}`));
|
|
|
|
client.on('warn', (e) => (`[WARN] ${e}`));
|
2022-04-21 20:53:03 -05:00
|
|
|
client.once('ready', async () => {
|
2022-04-22 15:01:17 -05:00
|
|
|
const sandboxSettings = config.sandbox;
|
|
|
|
const localCommands = client.guilds.cache.get(sandboxSettings.id)?.commands;
|
|
|
|
const globalCommands = client.application.commands;
|
2022-05-01 20:11:30 -05:00
|
|
|
let existingLocal = await localCommands?.fetch();
|
|
|
|
let existingGlobal = await globalCommands?.fetch();
|
2022-04-21 20:53:03 -05:00
|
|
|
|
2022-04-22 15:01:17 -05:00
|
|
|
if (sandboxSettings.enabled) {
|
|
|
|
if (sandboxSettings.refreshLocal) {
|
|
|
|
console.log('deleting previous local commands');
|
2022-05-01 20:11:30 -05:00
|
|
|
existingLocal?.forEach(async x => {
|
|
|
|
await localCommands?.delete(x);
|
2022-04-22 15:01:17 -05:00
|
|
|
});
|
|
|
|
existingLocal = new Discord.Collection();
|
|
|
|
}
|
2022-04-21 20:53:03 -05:00
|
|
|
|
2022-04-22 15:01:17 -05:00
|
|
|
if (sandboxSettings.refreshGlobal) {
|
|
|
|
console.log('deleting previous global commands');
|
2022-05-01 20:11:30 -05:00
|
|
|
existingGlobal?.forEach(async x => {
|
|
|
|
await client.application?.commands.delete(x);
|
2022-04-22 15:01:17 -05:00
|
|
|
});
|
|
|
|
existingGlobal = new Discord.Collection();
|
|
|
|
}
|
|
|
|
}
|
2022-04-21 20:53:03 -05:00
|
|
|
|
2022-04-22 15:01:17 -05:00
|
|
|
client.commands.forEach(async command => {
|
2022-05-01 20:11:30 -05:00
|
|
|
if (sandboxSettings.enabled && !existingLocal?.map(x => x.name).includes(command.name)) {
|
|
|
|
await localCommands?.create(command);
|
2022-04-22 15:01:17 -05:00
|
|
|
// console.log(`created new local command ${command.name}`);
|
|
|
|
}
|
2022-05-01 20:11:30 -05:00
|
|
|
if (!existingGlobal?.map(x => x.name).includes(command.name)) {
|
|
|
|
await globalCommands?.create(command);
|
2022-04-22 15:01:17 -05:00
|
|
|
// console.log(`created new global command ${command.name}`);
|
|
|
|
}
|
|
|
|
});
|
2022-04-21 20:53:03 -05:00
|
|
|
|
2022-04-22 00:11:53 -05:00
|
|
|
console.clear();
|
2022-04-18 11:03:01 -05:00
|
|
|
console.log(' ___ _ __ ');
|
|
|
|
console.log(' / | ____ (_) /__________ _ __');
|
|
|
|
console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/');
|
|
|
|
console.log(' / ___ |/ / / / / /_/ / / /_/ /> < ');
|
|
|
|
console.log('/_/ |_/_/ /_/_/\\__/_/ \\____/_/|_| ');
|
|
|
|
console.log(`${config.release}, ${config.build}`);
|
2022-04-21 18:09:21 -05:00
|
|
|
console.log('Bot online. | Anitrox by IDeletedSystem64 | ALL MY CODE KEEPS BLOWING UP!');
|
2022-04-18 11:03:01 -05:00
|
|
|
// Statuses
|
|
|
|
setInterval(async () => {
|
|
|
|
// Picks a status from the config file
|
|
|
|
const index = Math.floor(Math.random() * config.statuses.length);
|
2022-05-01 20:11:30 -05:00
|
|
|
await client.user?.setActivity(config.statuses[index]);
|
2022-04-18 11:03:01 -05:00
|
|
|
}, 20000);
|
2021-02-11 21:39:01 -06:00
|
|
|
});
|
2022-03-17 21:47:23 -05:00
|
|
|
|
2022-03-18 11:04:08 -05:00
|
|
|
// Begin Command Handler
|
2022-04-21 11:29:04 -05:00
|
|
|
client.on('messageCreate', async (message) => {
|
2022-04-18 11:03:01 -05:00
|
|
|
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
|
2022-03-26 03:33:18 -05:00
|
|
|
|
2022-04-18 11:03:01 -05:00
|
|
|
const args = message.content.slice(config.prefix.length).split(/\s+/);
|
|
|
|
const command = args.shift().toLowerCase();
|
2022-04-21 18:09:21 -05:00
|
|
|
|
2022-04-18 11:03:01 -05:00
|
|
|
if (!client.commands.has(command)) return;
|
2021-02-11 21:39:01 -06:00
|
|
|
|
2022-04-18 11:03:01 -05:00
|
|
|
try {
|
2022-04-21 23:44:02 -05:00
|
|
|
await client.commands.get(command).parseMessage(client, config, message, args);
|
2022-04-18 11:03:01 -05:00
|
|
|
} catch (error) {
|
2022-04-21 23:44:02 -05:00
|
|
|
console.log(error);
|
2022-04-21 18:09:21 -05:00
|
|
|
message.channel.send({
|
|
|
|
embeds: [{
|
|
|
|
title: '<:AnitroxError:809651936563429416> **Something went wrong!**',
|
|
|
|
description: error.stack,
|
|
|
|
color: 13632027,
|
|
|
|
footer: {
|
|
|
|
icon_url: message.author.displayAvatarURL(),
|
|
|
|
text: config.footerTxt
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
2022-04-18 11:03:01 -05:00
|
|
|
}
|
2021-02-11 21:39:01 -06:00
|
|
|
});
|
|
|
|
|
2022-04-21 23:44:02 -05:00
|
|
|
client.on('interactionCreate', async (interaction) => {
|
|
|
|
client.commands.get(interaction.commandName).parseInteraction(client, config, interaction);
|
|
|
|
});
|
|
|
|
|
2022-04-21 18:09:21 -05:00
|
|
|
client.login(config.token);
|