Facebook
From Scorching Pintail, 3 Years ago, written in Plain Text.
This paste is a reply to Untitled from Ungracious Curlew - view diff
Embed
Download Paste or View Raw
Hits: 88
  1. const Discord = require('discord.js');
  2.  
  3. const client = new Discord.Client();
  4.  
  5. client.commands = new Discord.Collection
  6.  
  7. const { token, prefix } = require('./botconfig.json');
  8.  
  9. const fs = require('fs');
  10.  
  11. const greyColor = ('#5c5c5c')
  12.  
  13. ////////////////////////////////////////////////////////
  14.                 //Command Handler//
  15.  
  16. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  17.  
  18. for (const file of commandFiles) {
  19.     const command = require(`./commands/${file}`);
  20.  
  21.     client.commands.set(command.name, command)
  22. }
  23.  
  24. ////////////////////////////////////////////////////////
  25.                     //BOT LOGGING IN//
  26.  
  27. client.on('ready', () => {
  28.     console.log(`${client.user.tag} successfully logged in!`)
  29.     client.user.setPresence({
  30.         status: 'dnd',
  31.         activity: {
  32.             name: `Use !help`,
  33.             type: 'WATCHING',
  34.         }
  35.     })
  36. })
  37.  
  38.  
  39. ////////////////////////////////////////////////////////
  40.        //message handler and prefix detection//
  41.  
  42.  
  43. client.on('message', message => {
  44.  
  45.     if (!message.content.startsWith(prefix) || message.author.bot) return;
  46.  
  47.     const args = message.content.slice(prefix.length).split(/ +/);
  48.  
  49.     const commandName = args.shift().toLowerCase();
  50.  
  51.     const command = client.commands.get(commandName) || client.commands.find
  52.  
  53.     (cmd => cmd.aliases && cmd.aliases.includes(commandName));
  54.    
  55.     try {
  56.  
  57.         command.run(message, args);
  58.  
  59.     } catch (error) {
  60.  
  61.         console.error(error);
  62.  
  63.         const commandErrorEmbed = new Discord.MessageEmbed()
  64.         .setTitle('Error whilst executing this command. . .')
  65.         .setColor(greyColor)
  66.         .setTimestamp()
  67.         .setFooter('All rights reserved • OG Development', 'https://i.imgur.com/wMdKQYB.png')
  68.         .addField('Reasons for the error are likely:', '• An unknown command\n• Command not entered correctly\n• An internal Error has occured')
  69.  
  70.         message.reply(commandErrorEmbed);
  71.     }
  72. })
  73.  
  74. client.login(token)