Skip to main content

How to build a discord bot and deploy it using Humalect?

ยท 5 min read
Priyansh Khodiyar

Discord bots are helpful artificial intelligence that can carry out a number of useful activities automatically on your server. That entails greeting any new participants, expelling disruptive individuals, and moderating the conversation. Several bots can even add games or audio to your server.

In this tutorial, we will see how can we deploy a sample Discord Bot application in a few clicks using the Humalect platform.

Let's get started

Example Discord Bot applicationโ€‹

Fork THIS sample Discord Bot repository to get started.

Click on THIS link to get an invite to see the bot in action (it mirrors whatever your say.)

Humalect Account Setupโ€‹


Please skip to point 5 if you have setup your Humalect account and have a functional K8s cluster.

  1. Sign up: visit and sign up. Complete the registration flow and log in.

  2. Integrate your Cloud Provider: Connect AWS/Azure by visiting THIS link and following their respective workflows.

  3. Integrate your source code provider: Visit THIS link, follow the respective workflow to connect Bitbucket/Github/GitLab.

  4. Create a Kubernetes Cluster: Create a k8s cluster by referring to our AWS or Azure docs.

  5. Create an environment

An environment is a logically isolated k8s namespace that contains all your deployment related entities for a pipeline.

Create an environment for your Go application. Check for various options that need to be configured to create a new environment or use an existing one.


These are some important fields:

  • Name of the environment that you wish to created: can be dev, prod or test etc.
  • Cluster in which you want to create this environment
  • The namespace in the k8s cluster that will host this environment
  1. Create a project.

A project maps the cluster and the code repository which needs to be deployed.

Refer the image below for various options that need to be configured to create a project.


  1. Create a pipeline.

After creating your project, let's now create a pipeline to define few of the below things for our deployment:

  • The subdomain on which you need your deployment to go live.
  • The port on which your code runs.
  • The branch from your code repo that you want to deploy.
  • The environment that you want to deploy to.
  • Whether you want to enable continuous deployments.
  • The environment variables for your app.

Refer the image below for various options that need to be configured to create a pipeline.




Advanced Options:

  • You can use the Dockerfile available in the git repo, check the box use Docker from source code.
  • Leave the autogenerated k8s YAML files, you can edit them if you wish (this can break things, edit only if you are aware of consequences)

Refer the image below for advanced options related to a pipeline.


  1. Deploy pipeline.

Once your pipeline is created, hit the deploy pipeline button to deploy your app. If you have enabled continuous deployments while pipeline creation, all your future commits will be automatically deployed.

Refer image below for pipeline deployment.


  1. See that your app is live.

Hit the See Deployment link next to your latest deployment and it will take you to the URL of your deployed application. The SSL certificates are auto-generated for you.

Refer image below for live deployment.


  1. Check logs and metrics.

Hit the Show Metrics and Logs button to view happenings of your latest deployment.

Refer image below for live deployment logs and metrics.


We are done!

Happy deploying!

Working of the Discord Bot:โ€‹

So far we have seen how to deploy your bot using Humalect, now lets dive into some technical details about the bot itself.

Here's the simple Dockerfile we wrote to run the bot in a Docker conatiner.

#Deriving the latest base image
FROM python:latest

RUN pip3 install
RUN pip3 install python-dotenv


COPY *.py ./

CMD [ "python", "./"]

Below is the driver file for the bot.
import bot

if __name__ == '__main__':

Below is the response of the bot when user enters a prompt.
def handle_response(message) -> str:
p_message = message.lower()

if p_message:
return p_message

return 'I do not know, trust me'

Below is the main logic for the bot.
import discord
import responses
import os

from dotenv import load_dotenv


TOKEN = os.getenv("TOKEN")

# Send messages
async def send_message(message, user_message, is_private):
response = responses.handle_response(user_message)
await if is_private else await

except Exception as e:

def run_discord_bot():

client = discord.Client(intents=discord.Intents.default())

async def on_ready():
print(f'{client.user} is now running!')

async def on_message(message):
# Make sure bot doesn't get stuck in an infinite loop
if == client.user:

# Get data about the user
username = str(
user_message = str(message.content)
channel = str(

# Debug printing
print(f"{username} said: '{user_message}' ({channel})")

# If the user message contains a '?' in front of the text, it becomes a private message
if user_message[0] == '?':
user_message = user_message[1:] # [1:] Removes the '?'
await send_message(message, user_message, is_private=True)
await send_message(message, user_message, is_private=False)

# Remember to run your bot with your personal TOKEN

How to get Token for your Discord botโ€‹

  1. Goto and create an application.
  2. Click on the application you created and go to to generate the TOKEN.
  3. Setup OAuth2 > URL Generator. Select Bot from Scopes and give the bot some permissions (or all).


  1. Below you'll find the generated URL to add the bot your servers.

As this tutorial is not on how to make a discord bot, refer to this link for full explanation of the same.

That wraps up for this tutorial.

Feel free to Reach out to us in case you need help.