Making your bot online

In the last guide, we talked about how to get your application/bot ready. In this guide, we will show you how to make your bot online, with the importing and the actual coding of the bot in node.js. We will talk about 24/7 hosting.

Importing packages required

In a windows 10 or mac, make sure that the latest version of node.js command prompt is installed and have npm enabled in set up wizard. Create a folder with a name my-discord-bot

Mainly, the only required package is discord.js. Type in the following code:

index.js
const Discord = require("discord.js")
//do npm install discord.js in node.js command prompt to make the code work
const client = new Discord.Client()

All of the code in this guide is in index.js

There is a library made by our team that make coding a discord bot easier. See the official documentation for using it.

The ready event and login method

Now that we imported the package, let's move on to the ready event and login method.

The ready event will be emitted when the bot is ready to ready message and do action. The game setting method and a lot of other method will go in here. They will be included in some later guides. Here are the example code below:

index.js
client.on("ready", () => {
    console.log(`${client.user.tag} is ready to server ${client.guilds.size} servers!`)
})

But the ready event requires a bot to be logged in. You could do that with the following code:

index.js
client.login("token")
//Change 'token' to your own bot token you get in discord developer portal

So I guess that is it for this guide! in the next guide, we will talk about 24/7 hosting.

Last updated