How to Build Your First Discord Bot with Node.js

3D ad banner ad revenue ad revenues adobe XD Advanced advanced-css-tools agency Agile Agile Development Ajax AlexW analytics Angelap angular AngularJS Animation anime.js ANN api apollo Appsflyer artificial neural network Async async components Avocode AWS AWS Lambda axios b2b b2c baas Banner banner ad Bannersnack bawmedia bem Blogs bootstrap bot browser testing build process bundler Business business success Canvas & SVG career Career Advancement charting chat app chatbots ChatKit chrome chrome extension chrome extensions ciphering cli cli tools clojure cloud hosting CloudFlare Cloudways cms CNN code challenge ColinI compiler components content context api convoluted neural network cron job cross browser testing cross platform development cross-browser CSS CSS Architecture css challenge css framework css frameworks css grid css modules CSS-in-JS D3.js data visualization databases debugging decoupled cms deep linking Design Design & UX design career design handoff dev environment DevOps devtools diagnostic analytics digit recognition digital agency digitalocean Discord Docker Docker Containers E-commerce edge computing Entrepreneur Entrepreneurship es6 eslint Expo Express FaaS Feathers Feathers.js figma flatfile framework Frameworks freelancing functional programming functions gatsby generators gitCS github github API GraphCMS graphing graphql Growth Grunt Gulp haskell headless CMS hooks hosting HTML HTML & CSS html preprocessor HTML5 IAAS Illustration ionic jade jamesh JavaScript javascript framework javascript frameworks Jest joelf jQuery jquery4u Keras lambdatest launch checklist Layout Learn-Node-JS learn-vue linux linux containers location tracking Managed managed hosting marvel MBaaS mekanism mind map mind mapping mindmapping Mobile mobile attribution Mobile Design modernjs modernjs-hub modernjs-tools monday mongodb multi-threading nest nilsonj node node version manager node-hub Node-JS-Tools Node-JS-Tutorials Node.js nodejs noops npm octobercms online publishing PaaS Package Management package manager Percy portfolio portfolio builders preprocessors prettier product design Profitability Programming PubNub Pug Pusher python Quasar quote builders Raw JavaScript React react components React Hooks React native read offline Reat native elements Recurring Payments RedBox redux Resources REST restful api Review SaaS sass self sencha serverless serverless computing shared hosting sharing state side project siteground sketch slashdata Software specifications sponsored state state management static module bundler StudioWorks Styled Components styling React components survey svelte sympli Tailwind task runner telegram bots Template engine Testing Themes Tic Tac Toe Tinder Tools & Libraries TypeScript Ubuntu UI UI Design Usability user experience user research UX ux issues vanilla javascript virtual machine visual testing vps vue Vue CLI vue dev environment vue-hub vue-tutorials vue.js vuetify vuex WatermelonDB Web Web Design web hosting Web Hosting & Domains Web standards web workers webpack website builders WebSockets windows windows 10 home Windows Subsystem for Linux Windows Terminal wix women women in tech WordPress wordpress themes work workers workflow WPEngine WSL WSL2 YellowBox Zeplin

How to Build Your First Discord Bot with Node.js

Nowadays, bots are being used for automating various tasks. Since the release of Amazon's Alexa devices, the hype surrounding automation bots has only started to grow. Besides Alexa, other communication tools like Discord and Telegram offer APIs to develop custom bots.

This article will solely focus on creating your first bot with the exposed Discord API. Maybe the most well-known Discord bot is the Music Bot. The music bot lets you type a song name and the bot will attach a new user to your channel who plays the requested song. It’s a commonly used bot among younger people on gaming or streaming servers.

Let’s get started with creating a custom Discord bot.


  • Node.js v10 or higher installed (basic knowledge)
  • a Discord account and Discord client
  • basic knowledge of using a terminal

Step 1: Setup Test Server

First of all, we need a test server on which we can later test our Discord bot. We can create a new server by clicking the plus icon in the left bottom corner.

click create server

A pop-up will be displayed that asks you if you want to join a server or create a new one. Of course, we want to create a new server.

select create server

Next, we need to input the name for our server. To keep things simple, I've named the server discord_playground. If you want, you can change the server location depending on where you're located to get a better ping.

server name

If everything went well, you should see your newly created server.

new server

Step 2: Generating Auth Token

When we want to control our bot via code, we need to register the bot first under our Discord account.

To register the bot, go to the Discord Developers Portal and log in with your account.

After logging in, you should be able to see the dashboard. Let's create a new application by clicking the New Application button.

developer dashboard

Next, you'll see a pop-up that asks you to input a name for your application. Let's call our bot my-greeter-bot. By clicking the Create button, Discord will create an API application.

create application

When the application has been created, you'll see the overview of the newly created my-greeter-bot application. You'll see information like a client ID and client secret. This secret will be used later as the authorization token.

overview greeter bot

Now, click on the Bot menu option in the Settings menu. Discord will build our my-greeter-bot application and add a bot user to it.

add bot

When the bot has been built, you get an overview of your custom bot. Take a look at the Token section. Copy this authorization token and write it down somewhere, as we'll need it later to connect to our bot user.

bot tab overview

The post How to Build Your First Discord Bot with Node.js appeared first on SitePoint.

Original Article

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.