A Discord bot designed to streamline the support process on the official NestJS Discord server.
As people who usually answer questions on the official NestJS Discord server, we've experienced that sometimes users ask questions that have already been answered many times before.
There are some common cases, like when they post a new support request, they don't provide a minimal reproduction code, or sometimes they don't even share their code, and even if they do, they don't know how to put them in code blocks properly.
So we devised the idea of having a Discord bot with predefined and well-written Markdown content as slash commands to reply to users instead of repeatedly writing and explaining.
cp .env.example .env
Three DISCORD_APP_ID
, DISCORD_BOT_TOKEN
, and DISCORD_GUILD_ID
environment variables are required, and rest of
the configuration is located in config.yml
.
Currently, the bot doesn't support hot-reloading. Instead, the application should restart to apply the changes.
To build this project, you must install Golang in your system and execute the following command.
go build -trimpath -buildvcs=false -ldflags "-w" -o ./bin/utility-bot ./main.go
Please add the bot to the server using the invite link generated by the discord:invite
CLI command,
as the permissions within the link will likely change based on the features we may add.
docker compose --env-file ./.env up -d --build
# Generates an invite link to add the bot to servers
docker compose exec utility-bot ./utility-bot discord:invite
# Graceful shutdown
# docker compose down
# Removing the registered slash commands (in case of inconsistency between the configuration and the production)
# docker compose exec utility-bot ./utility-bot discord:clean
- Slash commands
- Once slash commands are registered, Discord will sort them alphabetically, regardless of their initial order in
config.yml
. - Once slash commands are registered or removed, they get updated instantly for the end-user because this project uses guild commands instead of global commands.
- Discord has a global rate limit of 200 application command creations per day, per guild.
- Bot will automatically register non-registered slash commands on bootstrap.
- Registered slash commands can be removed by
discord:clean
command. - Only one sub-command level is supported; for example,
foo bar
is valid.
- Once slash commands are registered, Discord will sort them alphabetically, regardless of their initial order in
- Markdown content
- Content within the slash commands can have a maximum of 2000 characters.
- The bot will cache Markdown content on memory to avoid spamming I/O.
- Moderators
- They can be defined by their unique Discord ID in
config.yml
. - They bypass rate-limit policies.
- They can execute
protected
commands inconfig.yml
.
- They can be defined by their unique Discord ID in
go test -v ./...
- DiscordGo - Provides low level bindings to the Discord chat client API
- Cobra - Commander for modern Go CLI interactions
- Viper - Complete configuration solution for Go applications
- Validator - Implements value validations for structs based on tags
- Zerolog - Zero allocation JSON logger
- Go-humanize - Formatters for units to human friendly sizes
- Testify - A toolkit with common assertions and mocks
- Prometheus Golang - Prometheus instrumentation library for Go apps