DEV Community

Cover image for How to Setup a Complete Discord.JS Template Through the Command Line
Elitezen
Elitezen

Posted on • Updated on

How to Setup a Complete Discord.JS Template Through the Command Line

Setting up a complete boilerplate for a Discord bot can often take a lot of time. From initial files for registering commands, handling commands/events, and templates for the various Discord interaction types, preparing the environment can easily take up to an hour!

I set off to create a command line interface for setting up a fully functional and ready to go Discord Bot which does the job for you in just a couple of minutes.

spawn-discord-bot

spawn-discord-bot is an NPM package for spawning a Discord bot. The template includes all the required files, along with handlers for the various Discord API components. Each command type contains an example file to help you get started.

The end result will be a directory as such:

Bot directory result

Getting Started

Open up your command line and navigate to the directory you wish to create your bot in.

Run the following command to begin:



npx spawn-discord-bot


Enter fullscreen mode Exit fullscreen mode

You may be asked to download the package first. Enter Y to do so.

Next, you will be asked to name your bot's folder. Insert a folder name, or hit enter to apply the default (my-discord-bot).

Terminal output example

You now need to pick the language of your Discord bot. Use the arrow keys and ENTER to pick.

Terminal output example

Your bot template will then download, it will only take a few seconds.

Configuring Your Bot

Next you will need to setup your bot's credentials and example commands.

Follow the steps provided by the command line to begin

Terminal output example

npm i will install the required dependencies for the template.

npm run configure will start the configure script which is what you will use to set your client's token, id, and guild id. Make sure you have these on hand and ready.

Terminal output example

Make note of the pasting hint

Registering Commands

Before we can turn on the bot, we must register the example commands. If you do not wish to use example commands, delete the example files and move on to the final step.

Run the following command to register:



npm run commands


Enter fullscreen mode Exit fullscreen mode

Commands will register globally by default. Use the local option to only register locally:



npm run commands local


Enter fullscreen mode Exit fullscreen mode

Logging In

Lastly, to turn your bot on:



npm start


Enter fullscreen mode Exit fullscreen mode

YOUR_BOT_NAME has logged in! will appear in the terminal.

And that is it! You now have a fully set Discord.JS client ready to go.

Top comments (0)