This tutorial requires the latest nodejs, Terminal/CMD, and a discord server to put it on.

https://nodejs.org/en

The first thing you’re gonna wanna do is create a file called bot.js and insert the following

[Linux and Mac: nano bot.js] [Windows: type nul > bot.js]

//This is the main code, do not change these
const Discord = require("discord.js");
const client = new Discord.Client();
const settings = require('./config.json');
//This is all for this line

Now that you have the main code in we need to add some commands, for this lesson I will be using basic command. Skip a few lines down from the main code and type in

//This will send a message in the console letting you know that its working 
client.on('ready', () => {
   console.log('Listening for your command');
});


client.on('message', message => {
  if (message.content.startsWith('MAW')) {
    message.reply('Studios');
  }
});

Now that you have a basic command its time to add in the final piece, at the end of your code, type in

//defined in the main code
client.login(settings.token)

Now that we have finished our code its time to set up the config. Start by creating a file called config.json and insert the following (Note: We will be doing the token later) Make sure the spacing is correct.

{
        "token":"Insert-token-here"
}

Now that we have completed the code and the config, we need to set up the package.json. Start by typing

npm init

and follow the instructions

first it will ask for the name you want your package to be, type in whatever name you want. (note: it cannot be capital letters or 2-worded.)

Now that you have set up the name, it will ask you about the version number. For this tutorial I will put in 0.0.1.

Next, you will want to type in a description for it, type in anything you want.

After you have done that it will ask about an entry point, but in bot.js.

Skip the next few until author and put in your desired name.

Put in the recommended for the license and you will be done.

Once you get the the confirm menu, type in yes.

Now that we have the package.json install we need to install discord.js onto it. All you have to do it type

npm install discord.js

Ignore where it says that it requires a peer of different things, you do not need them.

Next we want to create the bot, log into discord via the website and scroll to the bottom to where it says applications in developer

Press new application and type in your desired name

If you want you can fill in the description and put in a avatar image, but for this tutorial I will not.

Navigate to the sidebar and click bot. You will notice that you do not have one, so click add bot.

Now you need to click copy below the Reveal to show token button.

After you’ve done this go back to the config.json and paste it in the token.

Now that were almost done, we need to invite the bot to the server. Start by going to the link. MAKE SURE YOU REPLACE “INSERT-CLIENT-ID” WITH YOUR CLIENT ID IN THE DISCORD APPLICATIONS.

https://discordapp.com/oauth2/authorize?client_id=INSERT-CLIENT-ID&scope=bot&permissions=8

Now all you have to do is select the server you want it on, and select authorize.

All Done!

Now you’re done! Now just navigate to the folder and type

node bot.js