Build A Bot (DiscordJS) — Javascript Chatbots made easy

Prerequisites

There is not much that you need to start writing a bot for Discord using Javascript and while you could theoretically compose everything with copy and paste code snippets written by other people, I highly suggest some prior Javascript knowledge. Here is what you need apart from that.

  • A Discord Account & (desktop or web) Client
  • A Discord Server with “manage server” permission
  • Basic Terminal KnowHow
  • NodeJS version 10 or higher

First Steps — Discord Developer Portal

To write and use a bot, you need to register it as a new application/bot user with your Discord account. Go to the Discord Developers Portal (sign in) and create a “New Application”.

Project Setup

To get you started, I have prepared a small setup with a few simple commands and the basics on GitHub to start your development with the most useful default tools. You can grab the code from my repository and put it in a new folder for your own project.

TOKEN=7074lly-n07-my-70k3n

The initial code, diving into DiscordJS

Without changing a single line of code, you could now start the bot by either calling node src/index.js to execute the file or run the script from the package.json file npm start which basically does the same.

1) ping

2) check the prefix

3) !who am I

4) !whois asking?

Wrapping up

I think we’ve covered a lot of ground here today and you learned a few basic commands and ways to interact with user messages in addition to the setup process using the discord developer portal.

Some words about me:

If you want to see more of my work and progress, feel free to follow me and check out my other articles. If you clap feverishly for the articles you like most, it will be easier for me to decide which directions to pursue in following articles so use your ability to cast a vote for future content.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Konrad Abe

Konrad Abe

I’m a Web / App Developer & father 👨‍👩‍👧 doing freelance and part-time agency work since 2003, 💻 building stuff on the side 🕹 and attending conferences 🎟