Advertisement
Guest User

JS

a guest
Jun 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const botconfig = require("./botconfig.json");
  2. const Discord = require("discord.js");
  3. const fs = require("fs");
  4. const bot = new Discord.Client({disableEveryone: true});
  5. bot.commands = new Discord.Collection();
  6. let coins = require("./coins.json");
  7.  
  8. fs.readdir("./commands/", (err, files) => {
  9.  
  10.   if(err) console.log(err);
  11.  
  12.   let jsfile = files.filter(f => f.split(".").pop() === "js")
  13.   if(jsfile.length <= 0){
  14.     console.log("Couldn't find commands.");
  15.     return;
  16.   }
  17.  
  18.   jsfile.forEach((f, i) =>{
  19.     let props = require(`./commands/${f}`);
  20.     console.log(`${f} loaded!`);
  21.     bot.commands.set(props.help.name, props);
  22.   });
  23.  
  24. });
  25.  
  26.  
  27. bot.on("ready", async () => {
  28.   console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
  29.  
  30.   bot.user.setActivity("Darklord", {type: "WATCHING"});
  31.  
  32. });
  33.  
  34. bot.on("guildMemberAdd" , async member => {
  35.   console.log(`${member.id} joined the server.`)
  36.  
  37.   let welcomechannel = member.guild.channels.find(`name` , "welcome_leave");
  38.   welcomechannel.send(`LOOK OUT EVERYONE! ${member} has joined the party!`);
  39. });
  40.  
  41. bot.on("guildMemberRemove" , async member => {
  42.   console.log(`${member.id} left the server.`);
  43.   let welcomechannel = member.guild.channels.find(`name` , "welcome_leave");
  44.  welcomechannel.send(`GOOD RIDDANCE! ${member} has bailed on the server!`);
  45. });
  46.  
  47. if(!coins[message.author.id]){
  48.     coins[message.author.id] = {
  49.       coins: 0
  50.     };
  51.   }
  52.  
  53.   let coinAmt = Math.floor(Math.random() * 15) + 1;
  54.   let baseAmt = Math.floor(Math.random() * 15) + 1;
  55.   console.log(`${coinAmt} ; ${baseAmt}`);
  56.  
  57.   if(coinAmt === baseAmt){
  58.     coins[message.author.id] = {
  59.       coins: coins[message.author.id].coins + coinAmt
  60.     };
  61.   fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
  62.     if (err) console.log(err)
  63.   });
  64.   let coinEmbed = new Discord.RichEmbed()
  65.   .setAuthor(message.author.username)
  66.   .setColor("#0000FF")
  67.   .addField("💸", `${coinAmt} coins added!`);
  68.  
  69.   message.channel.send(coinEmbed).then(msg => {msg.delete(5000)});
  70.   }
  71. if(!coins[message.author.id]){
  72.  
  73.  
  74. bot.on("message", async message => {
  75.   if(message.author.bot) return;
  76.   if(message.channel.type === "dm") return;
  77.  
  78.   let prefix = botconfig.prefix;
  79.   let messageArray = message.content.split(" ");
  80.   let cmd = messageArray[0];
  81.   let args = messageArray.slice(1);
  82.  
  83.   let commandfile = bot.commands.get(cmd.slice(prefix.length));
  84.   if(commandfile) commandfile.run(bot,message,args);
  85.  
  86.  
  87.  
  88. });
  89.  
  90. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement