shababad

Discord.js Tutorial Part 2 | index.js

Apr 6th, 2021 (edited)
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Adding More Commands + Prefix | Discord.js Tutorial Part 2 \\
  2. // Credits to Shababad: https://www.youtube.com/channel/UCXR5Lcj1Vw_3sCuB54vosSw
  3. // Watch the tutorial here: https://youtu.be/8ALRuLd3hv4
  4.  
  5. const discord = require("discord.js"); // Define what discord is
  6. const Client = require("discord.js");
  7. const { token, prefix } = require("./config.json") // Parse data from config.json (token and prefix in this case)
  8. const bot = new discord.Client(); // Create a client which is the bot himselfs
  9.  
  10. bot.on('ready', () => { // When the bot gets online (ready event)
  11.     console.log("I am online now :3") // Print "I am online now :3" when the bot gets online
  12. });
  13.  
  14. bot.on('message', message => { // When a message has been sent (message event)
  15.     const args = message.content.slice(prefix.length).trim().split(/ +/g);
  16.     if (!message.content.startsWith(prefix)) return; // If the content of the message does not starts with the prefix, then ignore.
  17.     const cmd = message.content.toLowerCase().replace(prefix, ""); /* Define what a cmd is -> Is the message content with the prefix removed and lower cased
  18.         Example:
  19.         Given is the message content (string) => "!piNG"
  20.         The message content is "!piNG" (Random Captializations as example), the bot will lowercase the message content (!ping), then remove the prefix from the message content (ping).
  21.         The result will end up as the cmd */
  22.     if (cmd == "ping") { // Checks if the cmd is "ping"
  23.         message.reply("Pong! 🏓"); // if the cmd is ping the reply with a "Pong" in the channel where the message has been sent to.
  24.     } else if (cmd == "foo") { // If the cmd is not "ping", then check if the cmd is "foo"
  25.         message.reply("Bar"); // If the cmd is "foo", then reply with a "Bar"
  26.     }
  27. });
  28.  
  29. bot.login(token);
  30. // [ALWAYS SAVE AFTER MAKING CHANGES!] //
  31. // Type "node ." in the Terminal and hit enter to get the bot online
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×