Tutorial: Create your own Discord Bot

Requirements

  • You must have Node JS installed on your desktop or hosting.
  • You must have a text editor installed. (I recomment Atom)
  • You must have a discord account

Lets Get Started

{
"name": "discord-bot",
"version": "0.0.1",
"description": "My first discord bot.",
"main": "server.js",
"author": "your-name",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1",
"discord.js": "^11.5.1",
"fs": "^0.0.2"
}
}
{
"bot":"Njk0MDc0MTg4OTEwMTY2MDM2.XoLgtA.c34EBQzKTSKzGJCDNbYnR1JBP4M",
"prefix": "-"
}
const express = require("express");
const app = express();
const config = require("./config.json");
var server = require("http").createServer(app);
app.get("/", (request, response) => {
console.log(Date.now() + " Ping Received");
response.sendStatus(200);
});
const listener = server.listen(process.env.PORT, function() {
console.log("Your app is listening on port " + listener.address().port);
});
setInterval(() => {
}, 280000);
const Discord = require("discord.js");
const {Client, Attachment, Collection, RichEmbed } = require("discord.js");
const client = new Client({
disableEveryone: true
});
client.on("ready", () => {
console.log(
`Ready to serve on ${client.guilds.size} servers, for ${client.users.size} users.`
);
let activities = [
`${client.guilds.size} Guilds!`,
`${client.channels.size} Channels!`,
`${client.users.size} Members!`
],
i = 0;
setInterval(
() =>
client.user.setActivity(
`btc-help | ${activities[i++ % activities.length]}`,
{ type: "WATCHING" }
),
15000
);
});
client.on("message", message => {
if (message.author.bot) return;
// This is where we'll put our code.
if (message.content.indexOf(config.prefix) !== 0) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === 'hello') {
message.reply("Hey, How are you?");
}
});
client.login(config.bot);
npm install discord.js express http --save
node server.js

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store