/create-discord-bot

Create Discord bots using a simple widget-based framework.

Primary LanguageJavaScriptMIT LicenseMIT

Create Discord Bot

Discord Twitter Follow Ko-fi Patreon

Create Discord bots using a simple widget-based framework.

npx demo

Table of contents

Getting started

Setup bot

  1. Go to Discord's Developer Portal.
  2. Create a new application.

Take note of your bot's client ID. You will need this to invite your bot to a server.

  1. Go to the bot tab and add a bot user to your application.

Take note of your bot's token. You will need this in the next section.

  1. Invite your bot to a server using: https://discordapp.com/oauth2/authorize?scope=bot&client_id=DISCORD_BOT_CLIENT_ID_PLACEHOLDER

A Discord bot's client ID is not the same as its token. Keep your token and any file containing it private. If your token ever leaks or you suspect it may have leaked, simply regenerate a new token to invalidate your compromised token.

Create bot

npx peterthehan/create-discord-bot
cd my-discord-bot
npm start

Verify the bot is working by using the .ping command.

🎉 You're ready to create your own Discord bot! 🎉

Documentation

Command design

create-discord-bot includes a command widget. Follow the design of the ping command to start building your own commands.

Widget design

  • All widgets must live under the src/widgets folder.
  • All widgets must have a handlers folder.
  • A handlers folder can only contain event handler files.
  • All event handler files must be named exactly the same as the events found on the Client page.

An example file tree diagram of these requirements could look like:

src
├──widgets
│  ├──command
│  │  ├──handlers
│  |  |  ├──ready.js
│  |  |  └──message.js
│  ├──widget1
│  │  ├──handlers
│  |  |  ├──messageReactionAdd.js
│  |  |  ├──messageUpdate.js
│  |  |  └──other event handlers
│  ├──widget2
│  │  ├──handlers
│  |  |  ├──typingStart.js
│  |  |  ├──userUpdate.js
|  |  |  └──other event handlers
Widget diagram

Widgets

The following widgets can be used by this framework by adding them into the src/widgets folder:

Troubleshooting

  • Try node -v to check if you have the latest LTS version of Node.js (v12.x.x).
  • Try npm install if running the application outputs Error: Cannot find module '...'.

Visit for more help or information!

Discord server invite