2023-02-10 04:25:25 +00:00
|
|
|
/* eslint-disable no-case-declarations */
|
|
|
|
/* eslint-disable indent */
|
|
|
|
// dotenv for handling environment variables
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
dotenv.config();
|
|
|
|
const token = process.env.TOKEN;
|
|
|
|
|
|
|
|
// Discord.JS
|
2023-02-11 03:41:47 +00:00
|
|
|
const { Client, GatewayIntentBits } = require('discord.js');
|
2023-02-10 04:25:25 +00:00
|
|
|
const client = new Client({
|
|
|
|
intents: [
|
2023-02-11 03:41:47 +00:00
|
|
|
GatewayIntentBits.Guilds
|
|
|
|
]
|
2023-02-10 04:25:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Various imports
|
|
|
|
const fn = require('./modules/functions.js');
|
|
|
|
const strings = require('./data/strings.json');
|
2023-02-11 03:41:47 +00:00
|
|
|
const isDev = process.env.DEBUG;
|
|
|
|
const statusChannelId = process.env.STATUSCHANNELID;
|
2023-02-10 04:25:25 +00:00
|
|
|
|
|
|
|
client.once('ready', () => {
|
2023-02-11 03:41:47 +00:00
|
|
|
// Build a collection of slash commands for the bot to use
|
|
|
|
fn.collectionBuilders.slashCommands(client);
|
2023-02-10 04:25:25 +00:00
|
|
|
console.log('Ready!');
|
|
|
|
client.channels.fetch(statusChannelId).then(channel => {
|
|
|
|
channel.send(`${new Date().toISOString()} -- Ready`);
|
2023-02-11 03:41:47 +00:00
|
|
|
}).catch(err => {
|
|
|
|
console.error("Error sending status message: " + err);
|
2023-02-10 04:25:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// slash-commands
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
|
|
if (interaction.isCommand()) {
|
|
|
|
const { commandName } = interaction;
|
|
|
|
|
|
|
|
if (client.slashCommands.has(commandName)) {
|
|
|
|
client.slashCommands.get(commandName).execute(interaction);
|
|
|
|
} else {
|
2023-02-11 03:41:47 +00:00
|
|
|
interaction.reply('Sorry, I don\'t have access to that command.').catch(err => console.error(err));
|
2023-02-10 04:25:25 +00:00
|
|
|
console.error('Slash command attempted to run but not found: /' + commandName);
|
|
|
|
}
|
2023-02-11 03:41:47 +00:00
|
|
|
} else if (interaction.isButton()) {
|
|
|
|
switch (interaction.component.customId) {
|
|
|
|
case 'acceptrules':
|
|
|
|
await fn.buttonHandlers.acceptRules(interaction).catch(err => {
|
|
|
|
console.error("Error handling rule acceptance: " + err);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'waterpingrole':
|
|
|
|
await fn.buttonHandlers.waterPing(interaction).catch(err => {
|
|
|
|
console.error("Error handling water ping button: " + err);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'fruitpingrole':
|
|
|
|
await fn.buttonHandlers.fruitPing(interaction).catch(err => {
|
|
|
|
console.error("Error handling fruit ping button: " + err);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-02-10 04:25:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
client.login(token);
|