Home
  • Welcome
  • Frequently Asked Questions
  • Common Errors
  • Getting Started
    • Getting Started - Long Version
    • Getting Started - TL;DR
  • First Bot
    • Your First Bot
    • Adding a Config File
    • Command with arguments
    • A Basic Command Handler
    • A Better Basic Command Handler
    • Using Embeds in messages
  • Coding Guides
    • SQLite-Based Points System
    • Cleverbot Integration
    • Using Emojis
    • Making a Starboard
    • Tracking Used Invites
    • Using Audit Logs
  • Understanding
    • Events and Handlers
    • Collections
    • Roles and Permissions
    • Sharding
  • Examples
    • Making an Eval command
    • Miscellaneous Examples
  • Discord Webhooks
    • Webhooks (Part 1)
    • Webhooks (Part 2)
    • Webhooks (Part 3)
  • Video Guides
  • Other Guides
    • Installing and Using Atom
    • Using Git to share and update code
    • Using Environment Variables
    • Async / Await
Powered by GitBook
On this page
  • Create App and Bot Account
  • Pre-requisite software
  • Example Code
  • Launching the bot
  • Resources
  1. Getting Started

Getting Started - TL;DR

PreviousGetting Started - Long VersionNextFirst Bot

Last updated 3 years ago

This is the TL;DR version. If you wish for a long version with more explanations, please see

Create App and Bot Account

  • Go to the

  • Create a New Application, and give it a name

  • Click Bot, Add Bot then finally click Yes, do it

  • Visit https://discord.com/oauth2/authorize?client_id=APP_ID&scope=bot , replacing APP_ID with the Application ID from the app page, to add the bot to your server (or ask a server admin to do it for you). If you're wanting slash commands as well, add %20applications.commands to the end of the URL above.

  • Copy your bot's Secret Token and keep it for later

Pre-requisite software

Depending on the operating system you're running the installation will be slightly different.

  • nodejs (Version 16.6 and higher required, see or )

Once you have this all installed, create a folder for your project and install discord.js:

mkdir mybot cd mybot npm i discord.js

Example Code

The following is a simple ping/pong bot. Save as a text file (e.g. index.js), replacing the string on the last line with the secret bot token you got earlier:

const { Client, Intents } = require("discord.js");
// Since discord.js exports an object by default, we can destructure it. Read up more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
 
client.on("ready", () => {
  console.log("I am ready!");
});
 
client.on("messageCreate", (message) => {
  if (message.content.startsWith("ping")) {
    message.channel.send("pong!");
  }
});
 
client.login("SuperSecretBotTokenHere");

Launching the bot

In your command prompt, from inside the folder where index.js is located, launch it with:

node index.js

If no errors are shown, the bot should join the server(s) you added it to.

Resources

: For the love of all that is (un)holy, read the documentation. Yes, it will be alien at first if you are not used to "developer documentation" but it contains a whole lot of information about each and every feature of the API. Combine this with the examples above to see the API in context.

is another great channel with more material. York's guides are great, and he continues to update them.

: If you prefer video to words, Evie's YouTube series (which is good, though no longer maintained with new videos!) gets you started with bots.

: The official server for An Idiot's Guide. Full of friendly helpful users!

: The official server has a number of competent people to help you, and the development team is there too!

this guide
Discord.com Application Page
Windows
Linux
Discord.js Documentation
An Idiot's Guide
Evie.Codes on YouTube
An Idiot's Guide Official Server
Discord.js Official Server