Advertisement
Spexz

Client.js

Oct 21st, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, MessageEmbed, Collection } = require ('discord.js')
  2. const fs = require('fs')
  3. const prefix = ">"
  4. const memberAdd = require('./Events/guildMemberAdd');
  5. const memberRemove = require('./Events/guildMemberRemove');
  6. const Enmap = require('enmap');
  7. class RF71 extends Client {
  8.     constructor() {
  9.         super();
  10.         this.discord = require('discord.js')
  11.         this.commands = new Collection();
  12.         this.db = new Enmap({ name: "RF71DB" });
  13.     }
  14.  
  15.     commandHandler() {
  16.         const files = fs.readdirSync('./commands').filter(file => file.endsWith(".js"));
  17.         for(const file of files) {
  18.             const command = require(`../commands/${file}`);
  19.             this.commands.set(command.name, command)
  20.         }
  21.     }
  22.  
  23.     start(token) {
  24.         this.login(token);
  25.         this.commandHandler();
  26.         this.on('ready', () => console.log("Ready!"))
  27.         this.on('message', async(message) => {
  28.             let prefix = this.db.get(`${message.guild.id}-prefix`) || ">";
  29.             if(message.author.bot || !message.guild || !message.content.startsWith(prefix)) return;
  30.             const args = message.content.slice(prefix.length).trim().split(/ +/g)
  31.             const cmd = args.shift().toLowerCase();
  32.             const command = this.commands.get(cmd);
  33.             if(!command) return;
  34.             return command.run(this, message, args).catch(console.error)
  35.         })
  36.         this.on('guildMemberAdd', async(member) => {
  37.             memberAdd(this, member);
  38.         })
  39.         this.on('guildMemberRemove', async(member) => {
  40.             memberRemove(this, member);
  41.         })
  42. }
  43. }
  44.  
  45. module.exports = RF71;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement