Discord.js-bot-example

A simple bot example for discord.js beginners!

You can send issues to us, if there is any problems with our code! We are not responsible if you mess up on your code, if it is an error, comment or send us an issue.

Before you start anything, please setup your bot by following the steps below.

Before you start setting up your bot user by going to this tutorial.

After that you shall be good to go with the code.

First thing you have to do is to load up the discord.js library. You can load it up by just writing this simple line below:

const Discord = require('discord.js')

Then you will have to set up your bot. So the bot is simply your “Client”, as we have to setup the client, we will have to write this line below.

const client = new Discord.Client

Constant variable “Discord” is defined as the discord.js library if you wonder if “Discord” is defined or not

Then we will have to make the console send the message “bot is ready!” when the bot is online and ready. So we will write this below:

client.on("ready", () => {
  console.log('bot is ready!')
});

For the bot to be online, and ready, you will have to log it in using your TOKEN DO NOT SHARE YOUR TOKEN TO ANYONE, IT IS SIMPLY A PASSWORD THAT ALLOWS PEOPLE TO LOGIN INO THE BOT.

Write this line below:

client.login('token')

Then the bot shall be ready and online!

After that, you will have to make the bot RESPOND to your message. By entering it into the message event. By writing this code ON TOP OF THE client.login('token')!!!:

client.on("message", async message => {

if(message.content = "ping") {
message.reply('pong!')
}

});

After that your bot is a fully functioning bot!

If you want to check out the discord.js library, you can go here

If this is not helpful to you, check out these guides below:

Respitory Help

Here are some common issues that people will ask:

Some of the commands doesn’t have the full code.

Yes, we didn’t want to provide the full code in some of the commands like ban and kick. Yeah we get it, “I WANT THE FULL CODE! I WANT THE FULL CODE!” But we cannot give you the fullcode because we want you to figure it out by yourself. You can look up the discord.js library and you can find to make the full command.

There’s an error on a command.

You can send us the error at the issues page and we will try to fix the issue or error as soon as we can.

If you have an error on Changing the code, then we’re not responsible on fixing the errors for you, you should fix the problem BY YOURSELF.

How do i make the bot always online?

You will have to check this page on how to do it.

Sources

Source Name Source links
An Idiot’s Guide http://anidiots.guide
Discord.js Guide http://discordjs.guide
Discord.js http://discord.js.org
Glitch http://glitch.com

citation needed