Advertisement
Guest User

Untitled

a guest
May 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // require packages
  2. const Discord = require('discord.js');
  3. const fs = require('fs');
  4. require('dotenv/config');
  5.  
  6. // initialise are bot
  7. const bot = new Discord.Client();
  8. bot.commands = new Discord.Collection();
  9.  
  10. // import bot setting (data)
  11. let prefix;
  12. const token = process.env.TOKEN;
  13.  
  14.  
  15.  
  16. const firebase = require('firebase/app');
  17. const FieldValue = require('firebase-admin').firestore.FieldValue;
  18. const admin = require('firebase-admin');
  19. const serviceAccount = require('./serviceAccount.json');
  20.  
  21. admin.initializeApp({
  22.     credential: admin.credential.cert(serviceAccount)
  23. })
  24.  
  25. let db = admin.firestore();
  26.  
  27.  
  28. //read commands files
  29. fs.readdir('./cmds', (err,files) => {
  30.     if (err) {
  31.         console.log(err);
  32.     }
  33.     let cmdFiles = files.filter(f => f.split(".").pop() === "js");
  34.     if (cmdFiles.length === 0){
  35.         console.log("No files found");
  36.         return;
  37.     }
  38.     cmdFiles.forEach((f,i) => {
  39.         let props = require(`./cmds/${f}`);
  40.         console.log(`${i+1}: ${f} loaded`);
  41.         bot.commands.set(props.help.name, props);
  42.     })
  43. })
  44.  
  45.  
  46.  
  47.  
  48.  
  49. bot.on('ready', async () => {
  50.     console.log(`${bot.user.username} is online!`);
  51. //    bot.user.setActivity('@Matti3939#0121', { type: 'LISTENING' });
  52.  
  53.    
  54.         let statuses = [
  55.             `${bot.guilds.size} Servers`,
  56.             `over ${bot.users.size} users`,
  57.             `Visual Studio Code`
  58.         ]
  59.  
  60.         setInterval(function() {
  61.             let status = statuses[Math.floor(Math.random() * statuses.length)];
  62.             bot.user.setActivity(status, {type: "WATCHING"});
  63.         }, 8000);
  64.  
  65. });
  66. bot.on('message',msg => {
  67.  
  68.     db.collection('guilds').doc(msg.guild.id).get().then((q) => {
  69.         if (q.data){
  70.             prefix = q.data().prefix;
  71.         }
  72.     }).then(() => {
  73.  
  74.         if (msg.channel.type === "dm") return;
  75.         if (msg.author.bot) return;
  76.    
  77.         let msg_array = msg.content.split(" ");
  78.         let command = msg_array[0];
  79.         let args = msg_array.slice(1);
  80.    
  81.         if (!command.startsWith(prefix)) return;
  82.    
  83.         if (bot.commands.get(command.slice(prefix.length))){
  84.             let cmd = bot.commands.get(command.slice(prefix.length));
  85.                 if (cmd){
  86.                     cmd.run(bot,msg,args,db);
  87.                 }
  88.         }
  89.     })
  90. });
  91.  
  92. bot.on('guildCreate', async gData => {
  93.     db.collection('guilds').doc(gData.id).set({
  94.         'guildID' : gData.id,
  95.         'guildName' : gData.name,
  96.         'guildOwner' : gData.owner.user.username,
  97.         'guildOwnerID' : gData.owner.id,
  98.         'guildMemberCount' : gData.memberCount,
  99.         'prefix' : '!!'
  100.     });
  101. });
  102.  
  103.  
  104.  
  105. bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement