discord-bot/bot.js
Dominik Korsa 22140f003a Init
2018-12-10 20:55:59 +01:00

34 lines
No EOL
947 B
JavaScript

const Discord = require("discord.js");
const Enmap = require("enmap");
const fs = require("fs");
const client = new Discord.Client();
const config = require("./config.json");
client.config = config;
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.commands = new Enmap();
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Ladowanie komendy ${commandName}`);
client.commands.set(commandName, props);
});
});
if(!process.env.DiscordToken) {
throw new Error("Token not provided")
}
client.login(process.env.DiscordToken);