nodbot/index.js

61 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-06-26 21:38:18 +00:00
/* eslint-disable brace-style */
// Variable Assignment
const dotenv = require('dotenv');
2021-06-27 23:41:25 +00:00
dotenv.config();
2021-06-26 21:38:18 +00:00
const Discord = require('discord.js');
const client = new Discord.Client();
2021-06-28 03:20:21 +00:00
// const config = require('./config.json');
2021-07-06 21:42:19 +00:00
// const { prefix, logChannel, bootMessage, shutdownMessage } = require('./config.json');
2021-06-28 03:20:21 +00:00
2021-06-28 19:28:16 +00:00
// const owner = process.env.ownerID;
const giphy = require('giphy-api')(process.env.giphyAPIKey);
2021-06-28 03:20:21 +00:00
const functions = require('./functions.js');
2021-06-26 21:38:18 +00:00
client.once('ready', () => {
console.log('Ready');
client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error);
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-06-30 22:59:24 +00:00
// client.channels.fetch(logChannel)
// .then(channel => {
// channel.send(bootMessage)
// .then()
// .catch(err => console.error(err));
// })
// .catch(err => console.error(err));
2021-06-26 21:38:18 +00:00
});
2021-07-09 22:06:11 +00:00
client.login(process.env.TOKEN)
.then()
.catch(err => {
console.error(err);
console.log('Token: ' + process.env.TOKEN)
2021-07-09 22:07:42 +00:00
});
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
});