Skip to content

The First Steps

Anjan Nair edited this page Sep 27, 2020 · 2 revisions

FIRST STEPS

How do I start with creating a Discord bot?

Discord currently has the best documentation for creating a bot with ton of examples and documentation. It can be found here.

What is Node.js and npm?

Node allows developers like you and me to write Javascript programs that run in a computer environment (a server environment).

Npm is the package manager for Node.js. The discord.js package can be downloaded using npm. More packages can be found here

  1. Install Node from here - Node.js
  2. Install npm from here - npm

Ok I installed all this what next?

Do not develop your code without creating a separate folder for the project. I always insist on it. It eases the process and even keeps all files in order. So first step is create a folder and name it whatever you want. Call it Discordbot or Rufus, anything!

Keeping shift clicked right click in the folder and open the command terminal in the folder (can be powershell or cmd)

The above step may be different for MacOS and other OS users but the end result should be same, that is opening the command terminal in the path of the bot folder

Did that what's next?

Type npm init

  • Now name your package something (can be anything)
  • Version can be anything 1.0.0 is also good enough
  • Give the bot a small description
  • Entry point needs to the main file that is index.js
  • Git repository can be left empty so just hit enter
  • Keywords isn't necessary too you can skip it
  • License can be chosen from here
  • Confirm the package with a yes

TADA YOUR package.json FILE IS READY!

Wow great! Now how do I start with the bot?

Open the folder in your favorite code editor/IDE. I would highly recommend Visual Studio Code as it has a lot of good features and extensions.

After opening the folder create a file and name it index.js.

This is where your main code goes. Now open a new terminal in Visual Studio Code (Ctrl + Shift + `).

After it opens type in npm install discord.js --save. This installs the necessary discord.js package for your Discord bot.

Once you install these packages and run them, 2 new things will form node modules and package-lock.json. These aren't meant to be touched and its best to leave them as it is. Side note: I will recommend not touching package.json after it is created too if you don't know what it is.

You're all set! Head to the documentation and start learning!!