Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
10,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const bot = new Discord.Client();
  3. const token = "YOUR TOKEN";
  4. const PREFIX = "!";
  5.  
  6. const fs = require('fs');
  7. bot.commands = new Discord.Collection();
  8.  
  9. const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
  10. for(const file of commandFiles){
  11.     const command = require(`./commands/${file}`);
  12.  
  13.     bot.commands.set(command.name, command);
  14. }
  15.  
  16. bot.on('ready', () => {
  17.     console.log("The bot is active and ready to go!");
  18. });
  19.  
  20. bot.on('message', message => {
  21.     let args = message.content.substring(PREFIX.length).split(" ");
  22.  
  23.     switch (args[0]) {
  24.  
  25.         case "ping":
  26.             bot.commands.get('ping').execute(message, args);
  27.         break;
  28.  
  29.         case "hello":
  30.             bot.commands.get('hello').execute(message, args);
  31.         break;
  32.     }
  33.  
  34. });
  35.  
  36. bot.login(token);
  37.  
  38. ----- Command JS File -----
  39. module.exports = {
  40.     name: 'ping',
  41.     description: "says ping!",
  42.     execute(message, args){
  43.         message.channel.send('pong!');
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement