How to Host a Discord Bot on Heroku 24/7

in utopian-io •  7 years ago  (edited)

Repository

https://github.com/Carlososuna11/discord-example

What Will I Learn?

you will learn how to create a super simple discord bot and keep it connected to your discord server 24/7 for free.

Requirements

-A Discord Account.
-A GitHub Account.
-A Heroku Account.

Difficulty

  • Basic

Tutorial Contents


Creating your Bot on Discord:

Open the following link and login using your discord account: https://discordapp.com/developers/applications/me

Create a New Application.

Follow this instruction and Create a new application - Name Your App, Select an Avatar/Icon, and click "Create App."

Once the App is created, select it and Click on "Create a Bot User." Confirm and Choose "Yes. Do It!" on the box that pops up.

Make sure to take Note of the Client ID and Token. You will need these later when you begin programming your bot. Do not share this information!

Next you need to invite the Bot to your Discord Server using the following link:
https://discordapp.com/oauth2/authorize?&client_id=YOUR_CLIENT_ID_HERE&scope=bot&permissions=0

Replace YOUR_CLIENT_ID_HERE with the Client ID from your created Bot.

For a detailed walkthrough of this section, you can follow the following link:
https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token

Creating the Script:

Go with the following link to GitHub to create the repository: https://github.com/new

Then we will create 3 scripts within that repository, which are these three

This will be our script to program both the bot and its function within discord:

bot.js

const Discord = require('discord.js');

const client = new Discord.Client();

 

client.on('ready', () => {

    console.log('I am ready!');

});

 

client.on('message', message => {

    if (message.content === 'ping') {

       message.reply('pong');

       }

});

 

// THIS  MUST  BE  THIS  WAY

client.login(process.env.BOT_TOKEN);//where BOT_TOKEN is the token of our bot

Our .Json file ,If you do not know what a json file is, you can google here

package.json

{

  "name": "Test",

  "description": "Test",

  "version": "0.0.0",

  "main": "bot.js",

  "scripts": {

    "start": "node bot.js"

  },

  "dependencies": {

    "discord.js": "11.1.0",

    "request": "2.81.0"

  }

}

And the Procfile

Procfile

worker: node bot.js

The scripts should appear like this

Note: if when copying the files or finishing the entire tutorial you have an error, try copying directly the GitHub script Found at the beginning of the post.

Uploading the Script to Heroku:

Heroku is a platform as a cloud computing service that supports different programming languages.

We will take advantage of that Heroku service to keep our bot activated

We will create a new board where the script will be uploaded here the link:
https://dashboard.heroku.com/apps

Let's go to the resources section and select github

Here we select our GitHub repository
we will select enable automatic desploy

Now we have to select what script we are going to work on, for that we go to resources and in free dynos we deselect the web and activate the worker

And our script would be online and working, but now we need to tell the script which bot is the one that is going to be linked to the script, that's why we go for settings

Then we will find an option called config variables,
add a new variable whose key will be BOT_TOKEN and the value of that variable will be the token of our bot

Then that would be everything, and the script knows what the bot is going to look for, here is a picture with the result of the tutorial we just made

And that would be all friends, the possibilities are endless when creating a discord bot, I will show you, a tutorial at the same time!

Curriculum

This is my first project.



Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

@anonym0us, I gave you an upvote on your first post! Please give me a follow and I will give you a follow in return!

Please also take a moment to read this post regarding bad behavior on Steemit.

Thank you for your contribution.

  • You haven´t explained the sections of the code, it's important for the user to understand your tutorial well.
  • The tutorial is poorly structured.
  • There are parts of your tutorial that don´t have punctuation, and there are line breaks in the middle of sentences.

See in this tutorial an example of a good tutorial.

Your contribution has been evaluated according to Utopian rules and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post,Click here


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]