π€
Hans - Discord Bot
Discord Bot build with Discord.JS, TypeScript, and lots of
Invite hans to your server
You can invite the bot here
hans:nightly
image with the latest features.
The list of commands can be found here
Developing Hans
πͺ¬ NOTE: Please consider opening an issue and PR for bugs, suggestions or new features.
π
Prepare environment
Before running any command, run npm install
& cp .env.template .env
, fill all the env variables needed. To create your application, visit Discord's Developer Portal
πͺ¬ IMPORTANT: A MongoDB instance is needed for the bot to work. A free Atlas cluster should be more than enough (even for small bots & communities) for development.
An alternative is to spin a MongoDB instance yourself with Docker locally. Use docker compose up -d
command to start it. docker-compose down
to stop it.
MongoDB Compass is recommended. Your connection string should be mongodb://hans:S3cret@localhost:27017
π©πΌβπ» Development
npm run dev
Will start a development server with ts-node and nodemon for livereload. A bot Invite link will be displayed in the console. Use it to invite the bot to your server.
Slash commands
All commands (under src/commands
) are built with the Slash Command interaction.
πͺ¬ IMPORTANT: before developing commands, make sure you invite the bot to your server and the entry in mongodb
hans -> config
has the commandsDevGuild.id set to your server id.
All commands under the main folder are available globally (it will take a second to have them available) while the ones under bots-playground
are guild specific and are instantly deployed, use this folder for debugging & development purposes.
To deploy the commands: npm run slashDev
or npm run slash
in production.
πͺ¬ IMPORTANT: Since the command process is isolated, make sure to export the mongodb connection string to your current shell, ex:
export MONGODB_CONNECTION="mongodb://hans:S3cret@localhost:27017"
π§ͺ
Testing
For testing, we use Mocha with TS.
All the tests are under the /tests
directory. Right now they're none or a few, ideally, we should add more test coverage for command controllers.
npm run test
Will run all the tests.
π
Production
We have multiple environments for deploying your bot (see Deployment section below). The easiest way would be to clone the repo and do:
πͺ¬ IMPORTANT: Make sure to follow the
Prepare environment
section.
npm run build
To generate the application's build.
npm start
Will run the bot with the production environment.
Other deployments
With Docker
There's an image in the DockerHub at en3sis/hans
with the latest version or you can build your image. Build it locally with docker build -t en3sis/hans .
With Kubernetes
It's also possible to deploy the bot to a Kubernetes cluster, the necessary files are in the k8s
folder.
Steps:
- You'll need your K8S cluster, ofc ;P
- Create the namespace
kubectl apply -f k8s/namespace.yaml
- Run
cp k8s/secrets.template.yaml k8s/secrets.yaml
, fill it up and apply the secretskubectl apply -f k8s/secrets.yaml
- Deploy the workload
kubectl apply -f k8s/deployment.yaml