How to Host a Discord Bot on Heroku 24/7
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
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
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"
}
}
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: https://github.com/Carlososuna11/discord-example
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.
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it does not follow the Utopian Rules.
You can contact us on Discord.
[utopian-moderator]
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by carlososuna11 from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.