DudeThatsErin

sharding with index.js

Dec 5th, 2020 (edited)
678
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Require the necessary things and login to the bot.
  2. const Discord = require("discord.js");
  3. const moment = require('moment');
  4. const fs = require('fs');
  5. const config = require("./config.json");
  6. const prefix = config.prefix;
  7. const manager = require('./shards.js');
  8. const client = new Discord.Client();
  9. client.login(config.token);
  10.  
  11. // Read the Commands folder
  12. client.commands = new Discord.Collection();
  13. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  14.  
  15. // Include the other files we have
  16. for (const file of commandFiles) {
  17.     const command = require(`./commands/${file.slice(0,-3)}`)
  18.     client.commands.set(command.name, command);
  19. }
  20.  
  21. // Sets status upon bot being booted up & logged in.
  22. client.on("ready", () => {
  23.    client.user.setPresence({
  24.         status: "online",
  25.         activity: {
  26.             name: `${config.prefix}help`,  
  27.             type: "PLAYING"
  28.         }
  29.     }); // End of Setting Presence
  30.     console.log(`Reading file: ` + file.slice(0,-3));
  31.     // Sends embed when bot is reloaded
  32.     const onEmbed = new Discord.MessageEmbed() // WORKS!
  33.          .setColor('#000000')
  34.          .setFooter(`The bot has been successfully rebooted. 💜 If you have issues please ping cute.as.ducks#8061`);
  35.     let channel = client.channels.cache.find(c => c.id === '776192612671553578');
  36.      
  37.     channel.send(onEmbed);
  38. }); // End of setting status.
  39.  
  40. // Listens for messages.
  41. client.on('message', message => {
  42.     if (!message.content.startsWith(prefix) || message.author.bot) return;
  43.  
  44.     const args = message.content.slice(prefix.length).trim().split(/ +/);
  45.     const commandName = args.shift().toLowerCase();
  46.  
  47.     const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
  48.  
  49.     if (!client.commands.has(command)) return;
  50.  
  51. try {
  52.     client.commands.get(command).execute(message, args);
  53. } catch (error) {
  54.     console.error(error);
  55.     message.reply('there was an error trying to execute that command!');
  56. }
  57.  
  58.     if (!message.guild) return;
  59.  
  60. }); // End of listening for messages.
RAW Paste Data