Discord.js Rapid Tutorial

Condensed tutorial for experienced developers

Home Games Software In Your Browser Animation Tutorials Miscellaneous
This extremely condensed tutorial shows the steps for getting a Discord bot up and running using Node.js and Discord.js.
  1. Register a new Bot application at the Discord Developer Portal.
  2. Download and install Node.js for your platform. Make sure to also install npm.
  3. Create a new folder on your computer for the bot's files.
  4. Open a command prompt, cd to the folder, and run npm init. Follow the instructions, or press enter for all lines.
  5. Create a new file index.js. On *nix systems, you can do this with touch index.js
  6. With your terminal still in the folder, run npm install discord.js
  7. Paste this starter code into index.js (also available on the the official docs.)
    
      const Discord = require('discord.js');
      const client = new Discord.Client();
                        
      client.on('ready', () => {
          console.log(`${client.user.tag} logged in`);
      });
                        
      client.on('message', msg => {
          if (msg.content === 'ping') {
              msg.reply('Pong!');
          }
      });                 
      client.login('token');
                    
    Download sample code
  8. Replace token with your bot's token.
  9. Run node index.js to launch your bot

Ultra condensed

  1. Register bot.
  2. Download Node.js.
  3. mkdir discordbot && cd "$_"
  4. npm init -y
  5. npm install discord.js
  6. wget https://www.ravbug.com/tutorials/discordjs/index.js
  7. Replace token, run node index.js

Super-Ultra condensed

  1. Register bot and download Node.js.
  2. Replace the folder and token variables at the beginning as appropriate.
    folder=discordbot && token=your_token_here; mkdir $folder && cd "$_" && npm init -y && npm install discord.js && wget https://www.ravbug.com/tutorials/discordjs/index.js && sed "s/'token'/'$token'/g" index.js
  3. node index.js