Learn how to make a discord bot with node.js

To start you will need the following:

  • Discord account
  • Node.js (v10 or higher)
  • Some knowledge with node.js (Basic)
  • A host (optional)

Links:

https://disccord.com

https://nodejs.org

https://discord.com/developers/applications

First of all, go to discord developer applications and create a new application and then name it. After you do that go to bot tab and click on create.

There you will see alot of options and keys, we just need 2 things, the token and the client id

Note: NEVER SHARE YOUR TOKEN WITH ANYONE, IT ALLOWS THEM TO CONTROL YOUR BOT KEEP IT SAFE.

Image

Then to add the bot to your server go to this site and all you will need is the client id which should be in the General Information tab, with this site you can generate an invite for your bot to your server.

When your on the site put your information and select which perms you want to give your bot and click the link below.

Now you should see your bot in your server like this:

Image

It will appear offline and that's because we haven't started it yet.

Now after you downloaded the latest version of Node.js make a new folder and go inside, after that run CMD and type the following:

cd file-directory-name

Image


instead of file-directory-name put the directory name of the folder your bot is gonna be in.

Here is how to get the directory name:

Click on the folder name above

Image

and then copy it


after that go to the folder and make a file called config.json

in that file we are gonna put the following code

{
	"clientId": "your-client-id",
	"guildId": "your-guild-id",
	"token": "your-token-goes-here"
}


then make a file called index.js and in it we will have:

const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');


const client = new Client({ intents: [Intents.FLAGS.GUILDS] });


client.once('ready', () => {
	console.log('Ready!');
});


client.on('message', message => {
  if (message.content === '-ping') {  
    message.channel.send(`Pong!`);
  }
});


client.login(token);

Then save and go to the CMD and type:

npm install

then after its done

npm install discord.js

and it should take a second (This works on discord.js v12=<)

node index.js

and the bot should come online

If you need any support regarding the making of a bot join our discord 

https://discord.gg/sRY9YhF8Th