loading...
Cover image for Discord Bot Development

Discord Bot Development

liamtownsley profile image Liam Townsley ・2 min read

Discord is a commonly used chat app previously targetted towards Gamers, however this platform has been adopted by games studios such as Mojang, Epic Games and Roblox and many other communities.

Another feature of Discord is that they have an excellent API, I will be teaching you how to create a quick Discord bot using node.js and an npm package called discord.js.

Installing the essentials.

Before we start you will need to install node.js I would recommend the LTS version.

Installing discord.js

  • Create a folder on your Desktop named "DiscordBot" or whatever you would like to name it.
  • Enter the folder and open a Command Prompt window
    • Inside the Command Prompt enter the following: npm init -y && npm i discord.js --save It should look like this: Alt Text

Now that we have discord.js installed we can get on to making the bot.

Coding the bot

  • Create a file called index.js and open it in a code editor, I prefer Visual Studio Code.
  • Open the file in your prefered editor
  • Copy the base code below:

Getting your Discord Token

To use the Discord API and to make a bot user you need a Discord Application, to do this you can go to the Developer Panel and follow these steps.

  • Click on the "New Application" button and give your bot a name, then click "Create".
  • Click on "Bot" and then create a bot user.
  • Once your bot user has been created you can copy your token like this: Alt Text
  • Paste your token on line 4 where is says DISCORD TOKEN.

Starting your bot

Now that you have your basic bot ready you can attempt to start it, run this command in your folder echo node . > start.bat and then run the batch file. Once you see a message that says "The bot is now ready!" your bot has sucesfully connected to the Discord API.

Additional Features

If you would like to make your bot more functional, you can either read the Discord API Documentation and do raw calls to the API or the discord.js documentation.

If you would like another guide, you can read here.

Posted on by:

liamtownsley profile

Liam Townsley

@liamtownsley

Hi πŸ‘‹, I'm Liam! I am a developer from Scotland.

Discussion

markdown guide