Skip to content

A serverless Discord Bot template built for AWS Lambda based on Discord's slash commands and the slash-create library.

License

Notifications You must be signed in to change notification settings

ytausch/serverless-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-discord-bot

A serverless Discord Bot template built for AWS Lambda based on Discord's slash commands and the slash-create library.

Introduction

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

Credentials

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

Setup

  1. Login to the AWS Management Console
  2. 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
  3. Install the AWS SAM CLI. You can optionally also install the AWS Toolkit extension for your IDE.
  4. Clone this repository.
  5. 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 the src/commands_layer/nodejs/commands/helloCommand.js file. Note that global commands take up to one hour to update.
  6. Run npm install in the commands layer folder (src/commands_layer/nodejs)
  7. To build and deploy the application, run the following in your shell (alternatively use AWS Toolkit):
sam build
sam deploy --guided
  1. Copy the API Gateway endpoint URL stack output and paste it in the Discord Developer Portal as Interactions Endpoint URL.
  2. Have some fun and build something great!

Usage

Updating your commands

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.

Documentation

Releases

No releases published

Packages

No packages published