const discord = require("discord.js"); const botConfig = require("./botconfig.json"); const fs = require("fs"); const bot = new discord.Client(); bot.commands = new discord.Collection(); fs.readdir("./commands/" , (err, files) => { if (err) console.log(err); var jsFiles = files.filter(f => f.split(".").pop() === "js"); if (jsFiles.length <=0) { console.log("No files found") return; } jsFiles.forEach((f, i) => { var fileGet = require(`./commands/${f}`); console.log(`File ${f} loaded`) bot.commands.set(fileGet.help.name, fileGet) }) }); bot.on("ready", async () => { console.log(`${bot.user.username} is online`) bot.user.setActivity("Void Discord", {type: "PLAYING"}); }); bot.on("message", async message => { if(message.author.bot) return; if(message.channel.type === "dm"); var prefix = botConfig.prefix; var messageArray = message.content.split(" "); var command = messageArray[0]; var arguments = messageArray.splice(1); var commands = bot.commands.get(command.slice(prefix.length)); if(command) commands.run(bot,message, arguments); //if ( command === `${prefix}invitelink`){ // return message.channel.send("https://discord.gg/VfWCYhn"); //} if ( command === `${prefix}info`){ var botIcon = bot.user.displayAvatarURL; var botEmbed = new discord.RichEmbed() .setColor("#0000") .setThumbnail(botIcon) .addField("Name", bot.user.username) .addField("Created At", bot.user.createdAt) .addField("Member Count", message.guild.memberCount); return message.channel.send(botEmbed); } }); bot.on("guildMemberAdd", member => { const channel = member.guild.channels.find("name", "new-people"); if(channel) console.log("Kan kanaal niet vinden"); var joinMessage = new discord.RichEmbed() .setAuthor(`${member.user.tag}`, member.user.displayAvatarURL) .setDescription(`${member.user.username}, Welcome to **Void Community** discord. Do **!tryout** in chat to get the Needs Tryout role! Read our #faq and #rules! :wave:`) .setColor("#00ff0c") .setTimestamp() .setFooter("User joined"); channel.send(joinMessage) }); bot.on("guildMemberRemove", member => { const channel = member.guild.channels.find("name", "new-people"); if(channel) console.log("Kan kanaal niet vinden"); var joinMessage = new discord.RichEmbed() .setAuthor(`${member.user.tag}`, member.user.displayAvatarURL) .setColor("#ff0000") .setTimestamp() .setFooter("User leaved"); channel.send(joinMessage) }); bot.login(botConfig.token);