nodbot/index.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-06-26 21:38:18 +00:00
/* eslint-disable brace-style */
// Variable Assignment
2021-06-27 23:41:25 +00:00
const fs = require('fs');
2021-06-26 21:38:18 +00:00
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-27 23:41:25 +00:00
client.commands = new Discord.Collection();
const debug = true;
const config = require('./config.json');
const { prefix, serverID } = require('./config.json');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// const owner = process.env.ownerID;
2021-06-26 21:38:18 +00:00
2021-06-27 23:41:25 +00:00
function getCommandFiles() {
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
if (debug) console.log(client.commands);
}
2021-06-26 21:38:18 +00:00
2021-06-27 23:41:25 +00:00
function extCheck(content) {
const lastFour = content.slice(-4);
switch (lastFour) {
case '.gif':
return 'gif';
case '.jpg':
return 'jpg';
default:
return false;
}
2021-06-26 21:38:18 +00:00
}
client.once('ready', () => {
console.log('Ready');
2021-06-27 23:41:25 +00:00
client.guilds.fetch(serverID)
.then(guild => client.user.setActivity('Nod Simulator 2021', {type: "PLAYING"}))
.catch(console.error);
getCommandFiles();
2021-06-26 21:38:18 +00:00
});
client.login(process.env.TOKEN);
client.on('message', message => {
2021-06-27 23:41:25 +00:00
if (debug) console.log(extCheck(message.content));
if (!message.content.startsWith(prefix) || message.author.bot || !extCheck(message.content)) return;
2021-06-27 19:23:14 +00:00
2021-06-27 23:41:25 +00:00
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
2021-06-26 21:38:18 +00:00
2021-06-27 23:41:25 +00:00
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('There was an error trying to execute that command.');
2021-06-26 21:38:18 +00:00
}
});