const Discord = require("discord.js")
const config = require("./config.json")
const bot = new Discord.Client();
const fs = require("fs");
bot.commands = new Discord.Collection();
if(config.token === "setmeplease") return console.log("Set your token up! Go to https://www.discordapp.com/developers and generate a token from a bot user.");
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
console.log("Couldn't find commands.");
jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
console.log(bot.user.username + " is online.")
bot.on("message", async message => {
//a little bit of data parsing/general checks
if(message.author.bot) return;
if(message.channel.type === 'dm') return;
let content = message.content.split(" ");
let command = content[0];
let args = content.slice(1);
let prefix = config.prefix;
//checks if message contains a command and runs it
let commandfile = bot.commands.get(command.slice(prefix.length));
if(commandfile) commandfile.run(bot,message,args);