Template for serverless-discord that uses AWS Lambda and SQS to run a Discord bot. It has both an synchronous and an asynchronous command for an example of how to do either one. It is generally recommended to use async commands when possible because Lambda doesn't always return fast enough for Discord.
npm install
You will need to create a Discord application through the developer portal. Once you have your application created, you will also want to create a bot for the application to get a bot token.
Using the default KMS key on your AWS account, replace CHANGEME!!
with your public Discord key from the Discord developer website:
aws ssm put-parameter \
--name "serverless-discord-template/dev/DISCORD_PUBLIC_KEY" \
--value "CHANGEME!!" \
--type "SecureString"
aws ssm put-parameter \
--name "serverless-discord-template/dev/DISCORD_APPLICATION_ID" \
--value "CHANGEME!!" \
--type "SecureString"
aws ssm put-parameter \
--name "serverless-discord-template/dev/DISCORD_BOT_TOKEN" \
--value "CHANGEME!!" \
--type "SecureString"
cdk bootstrap aws://<your_aws_account_id>/<region>
cdk deploy
Go into the Discord developer portal and add the API Gateway URL that was output to Interactions Endpoint URL
field. When
you click save, it should verify that your application is properly setup.
Discord requires you to register your commands to use them. Luckily there is a helper included that is used in scripts/createCommands.ts
to handle the dirty work.
npm run deploy:discord
npm run build
compile typescript to jsnpm run test
perform the jest unit testsnpm run deploy:discord
registers the command with Discordnpm run lint
runs linting across the projectnpm run lint:fix
runs linting and fixes anything it cancdk bootstrap
bootstrap the cdk project to your accountcdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template