Advertisement
Guest User

Untitled

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