Let's set up a TypeScript package that uses the AWS CDK to deploy a Lambda function for handling Discord bot slash commands. Below is a step-by-step guide on how to structure your package and the necessary scripts.
Step by Step Guide
1. Pre-requisites
- AWS
- NodeJS
- Discord
2. Initialize your CDK project
mkdir discord-bot
cd discord-bot
cdk init app --language=typescript
3. Install necessary dependencies
npm install @types/aws-lambda dotenv discord.js discord-interactions
npm install -D typescript jest @types/jest @types/aws-lambda ts-jest esbuild
4. Add the following options to tsconfig.json
{
"compilerOptions": {
...
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
}
5. Create .env
file with following parameters copied
DISCORD_TOKEN=<YOUR_DISCORD_TOKEN>
DISCORD_CLIENT_ID=<DISCORD_CLIENT_ID>
DISCORD_PUBLIC_KEY=<DISCORD_PUBLIC_KEY>
6. update npm commands in package.json
"scripts": {
"clean": "rm -rf dist && rm -rf cdk.out",
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"register": "node dist/src/commands/register-commands.js",
"deploy": "npm run clean && npm run build && npm run register && cdk deploy"
},
7. Copy the files under lib
and src
// Copy the entire folder
8. Run the commands
npm run deploy
Top comments (0)