A serverless Discord Bot template built for AWS Lambda based on Discord's slash commands and the slash-create library.
This repository helps you to get started with a serverless AWSLambdaServer
setup if you want to use slash-create for your discord bot running on AWS.
It contains a CloudFormation template based on AWS SAM describing the following resources:
Name | Source Folder | Description |
---|---|---|
CommandsLayer |
src/commands_layer |
Lambda layer containing the slash-create library and your custom slash commands |
CreateCommandsFunction CreateCommandsInvoker |
src/create_commands |
Lambda function that automatically syncs your commands to Discord every time you update them |
DiscordInteractionApi |
- | Amazon API Gateway HTTP API receiving incoming interaction requests from Discord |
DiscordHandlerFunction |
src/handler |
Lambda function responsible for handling and executing your commands |
Discord credentials are retrieved from an AWS Secrets Manager secret named /dev/serverless_discord_bot/discord
you have to create manually before deploying the stack.
It must contain the following (self-explanatory) key/value pairs you get from the Discord Developer Portal:
app_id
public_key
bot_token
- Login to the AWS Management Console
- Create a new Secrets Manager secret
- Secret Type: other
- Add your Discord credentials (see above)
- Set the name of the secret to
/dev/serverless_discord_bot/discord
- Install the AWS SAM CLI. You can optionally also install the AWS Toolkit extension for your IDE.
- Clone this repository.
- Add your commands in
src/commands_layer/nodejs/commands
. For more information, refer to the docs linked below. For a quick demo, you can use the default hello command. To use it, set your guild id in thesrc/commands_layer/nodejs/commands/helloCommand.js
file. Note that global commands take up to one hour to update. - Run
npm install
in the commands layer folder (src/commands_layer/nodejs
) - To build and deploy the application, run the following in your shell (alternatively use AWS Toolkit):
sam build
sam deploy --guided
- Copy the API Gateway endpoint URL stack output and paste it in the Discord Developer Portal as Interactions Endpoint URL.
- Have some fun and build something great!
To update your commands, simply edit the code in the commands directory and deploy your changes. CreateCommandsFunction
will automatically be called and sync your changes to Discord.