Add Discord Bot to your Server | Code your Bot | Deploying Bot on Heroku |
Reveal Steps
Screens | Steps |
---|---|
1. Open Discord developers portal Click New Application |
|
2. Give your BOT a new name and click Create |
|
3. Customize your bot by giving an Image and description. | |
4. Under the Bot tab, click Add Bot |
|
5. Set Icon and Username |
|
6. Go to OAuth2 tab. Tick the bot checkbox under scopes.You can customize your BOT by setting the Bot Permissions. Note changing the permissions updates the link that'll be used to invite your bot to your server. |
|
Inviting Your Bot when you open the link from the step above, in a new tab you'll see the following page and now you can add the bot to any of your server |
find detailed steps here
Reveal Steps
-
You have to download docker and install the Remote - Containers extension in your vscode
-
Get your Bot's token, for this you must go back to the developer portal, select your bot and go to the
Bot
tab, there you can find your Bot'stoken
. -
The simplest way to code your bot would be to fork this repo and then work on
bot-template
branch. alternatively you can clone this repository specifically thebot-template
branch.$ git clone -b bot-template --single-branch https://github.com/NathanAlcantara/bot-template
-
Next create an
.env
file in the root of the repository and add yourtoken
like so:token=TOKEN_WHICH_YOU_GOT_FROM_DISCORD
the
.env
file takes in key and value pair so here the key is token, if you wish to give a different token name then make sure you update the same insrc/sonfig/secrets.ts
file, as it looks for the "token" key.export const DISCORD_TOKEN = process.env["token"];
-
Now it's time to start the project
Click on the Remote - Containers symbol (left inferior side
><
), selectOpen in Container
and see the magic happenWhen your workspace is ready you can start the bot:
$ yarn start
you can view the
NPM SCRIPTS
in thepackage.json
file, running the start command should compile your project and run the bot -
On Successfully building and running the project you'll see
🚀 Bot is on
You should now be able to see your Bot online in your discord Server.
-
To get you started the template consist of two commands
greet
andtime
to test your bot, go to any text channel of your server and type in;greet
, you'll see your bot reply as such -
To Add more commands you must add a new class in
src/commands
folder taking into referencegreetCommand.ts
file, then you should export the class using thesrc/commands/index.ts
file so you can easily import it from yoursrc/CommandHandler.ts
. -
You can update the "prefix" (
;
) of the bot from thesrc/config/botConfig.ts
file.
Reveal Steps
- Install Heroku Cli
- login with your Heroku account credentials when you run
$ heroku login
- Now create an app with name your-app-name by running:
$ heroku create your-app-name
- add a Git remote named heroku pointing to Heroku:
$ git remote add heroku https://git.heroku.com/your-app-name.git
Integrating Heroku with GitHub, This step is required if you plan on automatically deploying your bot every time you push changes to a GitHub repository. (detailed steps here)
- Select your app from the Heroku Dashboard.
- Go to
Deploy
tab of app,- Enabling GitHub integration: To configure GitHub integration, you have to authenticate with GitHub. You only have to do this once per Heroku account.
- App Connected to Github: you have to select the repository with your Bot.
- Automatic deploys: When you enable automatic deploys for a GitHub branch, Heroku builds and deploys all pushes to that branch.
Testing your setup, This step is not required, but it's highly recommended. You should build your application locally to test if you've set up it correctly.
$ heroku local
The Heroku CLI will now run your app at http://localhost:5000/; if no errors are encountered, you're on the right track!
-
Go to
Settings
tab of app to set your discord bot token inconfig vars
section. -
Deploying your bot Upon reaching this step you should have:
- developed a functioning Discord bot
- setup your repository for Heroku deployment
If all goes well, you can now deploy your app to Heroku by running:
$ git push heroku master
Note: If you have setup Automatic Deploys, you'll able to deploy your app with every commit to your master branch.
On completion of the above steps Heroku Cli will give you a link to your hosted app something like this:
https://you-app.herokuapp.com
. Most often than not you'll run into issues with your first deployment as might have some dependencies in dev-dependencies or some config issues.
if you run into any issues run
heroku logs --tail
find detailed steps here