Making a Discord Bot

If you have a Discord chat channel and want to make your own custom bot it seems somewhat difficult to start, especially if you haven’t programmed with node.js before. I will start this tutorial with the basics of node.js and show you how to start programming it. I assume you are using Windows 10.

INSTRUCTIONS

1) Go to http://discordapp.com/developers/. On the left panel select “My Applications”.

Click new application button. Type in an app name, press “Create Application” button.

On the next screen, click the “Create a Bot User” button.

untitled-2

untitled-3

Copy the client ID. Go to “https://discordapp.com/oauth2/authorize?&client_id=YYYY&scope=bot” (replace YYYY for the client ID). Give it access to your chat channel.

If you see the “Token:click to reveal”, click on that and copy the token.

2) Download/Install node.js LTS

3) Make a directory on your Desktop called myapp. Hold down the SHIFT key and right click on this folder. Select the option “Open command window here”.

4) Type in “npm install discordie”. This will make a new folder called “node_modules” which holds the Discordie repo files.

untitled-1

5) In the command window type in “npm init”. This will start the package.json making process. Hit enter for every option. Minimize the command window.

untitled-4

6) Open package.json with wordpad.

CHANGE:

“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1″
},

TO:

“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1″,
“start”: “node index.js”
},

7) Right click in the myapp folder and select New > Text document. Rename it to index.js, open it with notepad.
(you might need to enable show hidden extensions in folder view)

8) Type in the following:

var Discordie = require(“discordie”);
var Events = Discordie.Events;

var client = new Discordie();

client.connect({ token: “YOUR_TOKEN_GOES_HERE” });

client.Dispatcher.on(Events.GATEWAY_READY, e => {
console.log(“Connected as: ” + client.User.username);
});

client.Dispatcher.on(Events.MESSAGE_CREATE, e => {
if (e.message.content == “ping”)
e.message.channel.sendMessage(“pong”);
});

Replace YOUR_TOKEN_GOES_HERE with your token you copied from discordapp.com/developers page. Save and close.

Back to the command window. Type in “npm start”. Leave this command window open, go to your chat channel. You should see your bot in it. Send the message “ping”, your bot will respond with “pong”.

You can stop the bot by holding down “CTRL + C”. Use “npm start” whenever you want to start the bot back up.

You can now continue modifying the index.js file to make more commands and responses! If you want your bot to operate 24/7 I recommend signing up for a free node.js host service like OpenShift.