Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
115 lines (77 sloc) 3.03 KB
A simple discord bot guide

Basic Discord Bot


In order to run JavaScript code outside the browser we will use a Node.js. Make sure to install it for the correct operating system.

{% embed url="" %}

{% hint style="info" %} Use command: "node -v" in your terminal to check that you have successfully installed node.js on your system. {% endhint %}

It is also important that you create a bot account and add the bot to your server.

{% embed url="" caption="You can follow this guide to do so" %}

In order to code we will require a code editor. I highly recommend Visual Studio Code but you may use any that you prefer.

{% embed url="" %}


Go ahead a create a folder for your bot. We will be creating 2 files. index.js + config.json

In order to communicate with the Discord we will be using a library called discord.js. You can install it with the following command: npm i discord.js


{% code title="index.js" %}

//import modules
const Discord = require('discord.js');
const config = require('./config.json');

//initialize client
const client = new Discord.Client();

//ready event
client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}`);
    client.user.setActivity(`${config.prefix}help`, {type: 'PLAYING'})

//message event
client.on('message', message => {
    //to reduce code
    var cmd = message.content.slice(prefix.length);

    if (cmd === 'ping') {`Pong! \`${Math.floor(}ms\``);

    } else if (cmd ==='help') {
        //create new embed using this constructor
        helpEmbed = new Discord.RichEmbed()
        .setDescription('Help has arrived!');;

    } else if (cmd === 'reboot') {

        if ( !== config.ownerId) return;'Rebooting...');
        setTimeout(() => {
        }, 1000);


//token is hidden in config.json

{% endcode %}

{% hint style="info" %} The credentials in config.json are for example only. Please replace them with your own. {% endhint %}

{% code title="config.json" %}

    "prefix": "$",
    "ownerId": "123456789012345678",
    "token": "iafpiq3n8vi90navrnqwvrv21i.asdasdi3asdsgddag"

{% endcode %}

{% hint style="danger" %} Beware that revealing your token to anyone allows them to full access to your bot. {% endhint %}


In order to run the bot use command: node index.js


Here are some links that I personally find helpful with coding discord bots:

{% embed url="\#/" caption="Discord.js Documentation" %}

{% embed url="" %}

{% embed url="" %}

{% embed url="" caption="Great place to get help with discord.js" %}

You can’t perform that action at this time.