Hey guys! been a very long time since I wrote an Article on Dev!
for the previous couple of months I’ve been making an attempt to develop utilizing Typescript and host my very own apps.

Since Glitch.me determined to ban pinging companies like Uptime Robotic which was generally used to host Discord bots together with Glitch. So It was the right alternative to observe my Typescript on this Bot and host on Heroku.

So this is a brief and detailed article on how one can setup your individual discord Bots written in typescript.

hive-greeter-step-2 hive-greeter-step-3
Add Discord Bot to your Server Code your Bot Deploying Bot on Heroku



➡️ STEP 1: Add Discord Bot to your Server

Screens Steps
image 1. Open Discord builders portal

Click on New Utility

image 2. Give your BOT a brand new identify and click on Create
image three. Customise your bot by giving an Picture and outline.
image four. Below the Bot tab, click on Add Bot
image 5. Set Icon and Username
image 6. Go to OAuth2 tab.

Tick the bot checkbox below scopes.

You possibly can customise your BOT by setting the Bot Permissions.

Notice altering the permissions updates the hyperlink that’ll be used to ask your bot to your server.

image Inviting Your Bot
while you open the hyperlink from the step above, in a brand new tab you will see the next web page and now you possibly can add the bot to any of your server

discover detailed steps right here



STEP 2: Code your Discord Bot

  1. Get your Bot’s token, for this you could return to the developer portal, choose your bot and go to the Bot tab, there you’ll find your Bot’s token.
    image

  2. The best technique to code your bot could be to fork this repo after which work on bot-template department.
    alternatively you possibly can clone the repository particularly the bot-template department.

   $ git clone -b bot-template --single-branch https://github.com/MidasXIV/hive-greeter.git
  1. Subsequent create an .env file within the root of the repository and add your token like so:
   token=TOKEN_WHICH_YOU_GOT_FROM_DISCORD

the .env file takes in key and worth pair so right here the secret’s token, when you want to give a distinct token identify then be sure you replace the identical in src/sonfig/secrets and techniques.ts file, because it appears to be like for the “token” key.

   export const DISCORD_TOKEN = course of.env["token"];
  1. Now it is time to set up and construct the mission
   $ npm set up
   $ npm run begin

you possibly can view the NPM SCRIPTS within the package deal.json file, operating the beginning command ought to construct mission and run the bot on http://localhost:5000/; you possibly can modify the port in src/index.ts file.

  1. On Efficiently constructing and operating the mission you will see
   Server began on port 5000
   Hive Greeter has began

You must now be capable of see your Bot on-line in your discord Server.

  1. To get you began the template consists of two instructions greet and time to check your bot, go to any textual content channel of your server and kind in > greet, you will see your bot reply as such
    image

  2. To Add extra instructions you could add a brand new class in src/instructions folder taking into reference greetCommand.ts file, then you need to export the category utilizing the src/instructions/index.ts file so you possibly can simply import it out of your src/CommandHandler.ts.

  3. You possibly can replace the “prefix” ( > ) of the bot from the src/config/botConfig.ts file.



➡️ STEP three: Deploying Bot on Heroku

  1. Set up Heroku Cli
  2. login together with your Heroku account credentials while you run
   $ heroku login
  1. Now create an app with identify your-app-name by operating:
   $ heroku create your-app-name
  1. add a Git distant named heroku pointing to Heroku:
   $ git distant add heroku https://git.heroku.com/your-app-name.git

Integrating Heroku with GitHub, This step is required when you plan on routinely deploying your bot each time you push adjustments to a GitHub repository. (detailed steps right here)

  1. Choose your app from the Heroku Dashboard.
  2. Go to Deploy tab of app,
    • Enabling GitHub integration: To configure GitHub integration, it’s a must to authenticate with GitHub. You solely have to do that as soon as per Heroku account.
    • App Linked to Github: it’s a must to choose the repository together with your Bot.
    • Computerized deploys: Whenever you allow automated deploys for a GitHub department, Heroku builds and deploys all pushes to that department.
      image

Testing your setup, This step isn’t required, but it surely’s extremely really useful. You must construct your utility regionally to check when you’ve arrange it appropriately.

$ heroku native

The Heroku CLI will now run your app at http://localhost:5000/; if no errors are encountered, you are heading in the right direction!

  1. Go to Settings tab of app to set your discord bot token in config vars part.
    image

  2. Deploying your bot Upon reaching this step you need to have:

    • developed a functioning Discord bot
    • setup your repository for Heroku deployment

If all goes effectively, now you can deploy your app to Heroku by operating:

   $ git push heroku grasp

Notice: If in case you have setup Computerized Deploys, you will capable of deploy your app with each decide to your grasp department.

On completion of the above steps Heroku Cli provides you with a hyperlink to your hosted app one thing like this:
https://you-app.herokuapp.com. Most frequently than not you will run into points together with your first deployment as may need some dependencies in dev-dependencies or some config points.

when you run into any points run

heroku logs --tail

discover detailed steps right here

If you happen to come throughout any points, please do let me know within the feedback down under 🙂

you’ll find the repository right here:

GitHub logo

MidasXIV
/
hive-greeter

Discord bot created utilizing Typescrit and Discord js hosted on Heroku

hive-greeter-logo

hive-greeter-step-1 hive-greeter-step-2 hive-greeter-step-3
Add Discord Bot to your Server Code your Bot Deploying Bot on Heroku

STEP 1: Add Discord Bot to your Server

Reveal Steps

Screens Steps
image 1. Open Discord builders portal

Click on New Utility

image 2. Give your BOT a brand new identify and click on Create
image three. Customise your bot by giving an Picture and outline.
image four. Below the Bot tab, click on Add Bot
image 5. Set Icon and Username
image 6. Go to OAuth2 tab.

Tick the bot checkbox below scopes.

You possibly can customise your BOT by setting the Bot Permissions.

Notice altering the permissions updates the hyperlink that’ll be used to ask your bot to your server.

image Inviting Your Bot
while you open the hyperlink from the step above, in a brand new tab you will see the next web page and now you possibly can add the bot to any of your server

discover detailed steps right here

STEP 2: Code your Discord Bot

Reveal…

View on GitHub

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.