2021-06-26 21:38:18 +00:00
|
|
|
// Variable Assignment
|
2021-07-14 02:38:25 +00:00
|
|
|
// Environment Variable Setup
|
2021-06-26 21:38:18 +00:00
|
|
|
const dotenv = require('dotenv');
|
2021-06-27 23:41:25 +00:00
|
|
|
dotenv.config();
|
2021-07-14 02:38:25 +00:00
|
|
|
// Discord.js library
|
2021-06-26 21:38:18 +00:00
|
|
|
const Discord = require('discord.js');
|
2021-07-14 02:38:25 +00:00
|
|
|
// Create the client
|
2021-06-26 21:38:18 +00:00
|
|
|
const client = new Discord.Client();
|
2021-07-14 02:38:25 +00:00
|
|
|
// External Functions File
|
2021-06-28 03:20:21 +00:00
|
|
|
const functions = require('./functions.js');
|
2021-06-26 21:38:18 +00:00
|
|
|
|
2021-07-14 02:38:25 +00:00
|
|
|
// Once the client is logged in and ready
|
2021-06-26 21:38:18 +00:00
|
|
|
client.once('ready', () => {
|
|
|
|
console.log('Ready');
|
2021-07-14 02:38:25 +00:00
|
|
|
// This sets the activity that shows below the bot's name in the member/friend list
|
2021-06-28 00:24:58 +00:00
|
|
|
client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error);
|
2021-07-14 02:38:25 +00:00
|
|
|
// Import the Command, GIF, and Pasta files into collections
|
2021-06-28 03:20:21 +00:00
|
|
|
functions.getCommandFiles(client);
|
|
|
|
functions.getGifFiles(client);
|
2021-06-28 19:28:16 +00:00
|
|
|
functions.getPastaFiles(client);
|
2021-07-14 02:38:25 +00:00
|
|
|
// Get the owner and DM them a message that the bot is ready, useful for remote deployment
|
2021-07-14 01:14:50 +00:00
|
|
|
client.users.fetch(process.env.ownerID).then(user => {
|
|
|
|
user.createDM().then(channel => {
|
2021-07-14 02:38:25 +00:00
|
|
|
channel.send('Ready');
|
2021-07-14 01:14:50 +00:00
|
|
|
});
|
|
|
|
});
|
2021-06-26 21:38:18 +00:00
|
|
|
});
|
|
|
|
|
2021-07-14 02:38:25 +00:00
|
|
|
// Log into discord using the TOKEN provided by environment variables (.env)
|
2021-07-09 22:06:11 +00:00
|
|
|
client.login(process.env.TOKEN)
|
|
|
|
.then()
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err);
|
2021-07-14 02:38:25 +00:00
|
|
|
// Dump the TOKEN into the console as the TOKEN is likely the cause of any error logging in, unless Discord servers are down.
|
2021-07-09 22:06:11 +00:00
|
|
|
console.log('Token: ' + process.env.TOKEN)
|
2021-07-09 22:07:42 +00:00
|
|
|
});
|
2021-06-26 21:38:18 +00:00
|
|
|
|
2021-07-14 02:38:25 +00:00
|
|
|
// This runs on each message the bot sees
|
2021-06-26 21:38:18 +00:00
|
|
|
client.on('message', message => {
|
2021-06-30 22:59:24 +00:00
|
|
|
// Get the filename and extension as an array
|
|
|
|
const file = functions.getFileInfo(message.content);
|
|
|
|
if (!file) return;
|
|
|
|
// If the message is from a bot, or doesn't have a valid file extension, stop here.
|
|
|
|
if (functions.extIsValid(file.extension) == false || message.author.bot) return;
|
|
|
|
|
|
|
|
// If the command collection doesn't contain the given command, stop here.
|
|
|
|
if (!client.commands.has(file.extension)) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Attempt to execute the command
|
|
|
|
client.commands.get(file.extension).execute(message, file);
|
|
|
|
} catch (error) {
|
|
|
|
// Log errors and let the user know something went wrong.
|
|
|
|
console.error(error);
|
|
|
|
message.channel.send('There was an error trying to execute that command.');
|
2021-06-26 21:38:18 +00:00
|
|
|
}
|
2021-06-28 22:11:32 +00:00
|
|
|
|
2021-06-29 02:38:03 +00:00
|
|
|
// Try to delete the requester's message
|
|
|
|
if (message.deletable) {
|
|
|
|
message.delete().then().catch(err => console.error(err));
|
|
|
|
}
|
2021-06-26 21:38:18 +00:00
|
|
|
});
|