A personal Discord bot to handle miscellaneous tasks hosted on AWS Lambda.
| Command | Description |
|---|---|
/coinflip |
Flips a coin |
/ping |
Ping command |
/pz |
Manages the Project Zomboid server |
/roll |
Rolls dice with modifiers |
Run these commands from the project home directory:
- Endpoint Function:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags lambda.norpc -o binary/bootstrap ./cmd/endpoint/ - Task Function:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags lambda.norpc -o binary/bootstrap ./cmd/task/
Then compress each bootstrap binary into a separate ZIP file and upload each ZIP file to the related Lambda function.
- Copy
config.example.jsonto a new file, for exampledreamingway.json. - Add the values for your bot to the new file.
- Run this command from the project directory:
go run . --config dreamingway.json
NAME:
dreamingway - sync discord commands
USAGE:
dreamingway [global options]
GLOBAL OPTIONS:
--verbose, -v enable verbose logging (default: false)
--config string, -c string path to the configuration file (default: "config.json")
--config-string string configuration as a json string
--dry-run show the commands to publish, without any change to discord
--help, -h show help
Before you sync a config, run --dry-run to see what it will publish and delete. Discord does not change during a dry run.
One repository can serve several Discord bots. Each bot needs its own config file and its own Discord application.
go run . --config dreamingway.jsonThe endpoint and task binaries are identical for every bot. Bots differ only by their Lambda environment variables and their config file.
| Name | Description |
|---|---|
DEBUG |
Enable debug mode |
DISCORD_BOT_APPLICATION_ID |
Discord Bot Application ID |
DISCORD_BOT_PUBLIC_KEY |
Discord Bot Public Key |
DISCORD_BOT_TOKEN |
Discord Bot Token |
TASK_FUNCTION_NAME |
Name of the Task Lambda Function |
| Name | Description |
|---|---|
CLOUDFLARE_API_TOKEN |
Cloudflare API Token |
CLOUDFLARE_ZONE_ID |
Cloudflare Zone ID |
DISCORD_API_VERSION |
Discord API Version |
DISCORD_BOT_TOKEN |
Discord Bot Token |
PZ_DISCORD_ADMIN_ROLE |
Discord Admin Role for the Project Zomboid |
PZ_HOST |
Project Zomboid Host IP/URL |
PZ_HOST_INSTANCE_ID |
AWS Instance ID of the Project Zomboid Host |
PZ_HOST_REGION |
AWS Region of the Project Zomboid Host |
PZ_RCON_PASSWORD |
RCON Password of the Project Zomboid server |
PZ_RCON_PORT |
RCON Port of the Project Zomboid server |
To create dreamingway-bot on AWS, use the Terraform module.
- Create the endpoint Lambda function on AWS.
- For the
Runtime, selectAmazon Linux 2023. - For the
Architecture, selectarm64.
- For the
- Add an API Gateway trigger to the endpoint Lambda function.
- Use the following settings:
- Intent: Create a new API
- API type: HTTP API
- Security: Open
- Use the following settings:
- Create the task Lambda function on AWS.
- For the
Runtime, selectAmazon Linux 2023. - For the
Architecture, selectarm64.
- For the
- Build the endpoint and task binaries. Name each binary
bootstrap. - Compress each
bootstrapbinary into a separatebootstrap.zipfile. - Upload each ZIP file to the related Lambda function.
- In the
Configurationtab, add the required environment variables to each Lambda function. - Change the
Timeoutof the task Lambda function to more than 3 seconds.- Keep the
Timeoutof the endpoint Lambda function at 3 seconds. Discord requires a response in 3 seconds.
- Keep the
- Find the
API endpointvalue of the API Gateway trigger on the endpoint Lambda function. - Add this value to the
Interactions Endpoint URLfield of the bot in the Discord Developer Portal.
When you add the bot to a server, use the OAuth2 URL Generator. Give the bot these scopes and permissions:
applications.commandsbot
Manage Roles
