Advertisement
Guest User

JS

a guest
Jun 24th, 2018
73
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.  
  48.   }
  49.  
  50.  
  51.  
  52. bot.on("message", async message => {
  53.   if(message.author.bot) return;
  54.   if(message.channel.type === "dm") return;
  55.  
  56.   let prefix = botconfig.prefix;
  57.   let messageArray = message.content.split(" ");
  58.   let cmd = messageArray[0];
  59.   let args = messageArray.slice(1);
  60. }
  61.   let commandfile = bot.commands.get(cmd.slice(prefix.length));
  62.   if(commandfile) commandfile.run(bot,message,args);
  63.   if(!coins[message.author.id]){
  64.       coins[message.author.id] = {
  65.         coins: 0
  66.       };
  67.     }
  68.  
  69.     let coinAmt = Math.floor(Math.random() * 15) + 1;
  70.     let baseAmt = Math.floor(Math.random() * 15) + 1;
  71.     console.log(`${coinAmt} ; ${baseAmt}`);
  72.  
  73.     if(coinAmt === baseAmt){
  74.       coins[message.author.id] = {
  75.         coins: coins[message.author.id].coins + coinAmt
  76.       };
  77.     fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
  78.       if (err) console.log(err)
  79.     });
  80.     let coinEmbed = new Discord.RichEmbed()
  81.     .setAuthor(message.author.username)
  82.     .setColor("#0000FF")
  83.     .addField("💸", `${coinAmt} coins added!`);
  84.  
  85.     message.channel.send(coinEmbed).then(msg => {msg.delete(5000)});
  86. };
  87.  
  88.  
  89.  
  90. });
  91.  
  92. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement