{"id":15065942,"url":"https://github.com/gemisis/discord-bot-cdk-construct","last_synced_at":"2025-04-10T13:35:07.992Z","repository":{"id":42031289,"uuid":"350609781","full_name":"GEMISIS/discord-bot-cdk-construct","owner":"GEMISIS","description":"A CDK Construct for creating a serverless Discord bot. All you need to do is supply your code to handle the commands!","archived":false,"fork":false,"pushed_at":"2023-10-03T06:08:32.000Z","size":407,"stargazers_count":27,"open_issues_count":2,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T12:21:28.412Z","etag":null,"topics":["aws","aws-cdk","aws-cloudformation","aws-lambda","cdk","csharp","discord","discord-api","discord-bot","discord-js","discordapp","discordbot","discordjs","dotnet","java","nodejs","python","serverless","typescript"],"latest_commit_sha":null,"homepage":"https://constructs.dev/packages/discord-bot-cdk-construct/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GEMISIS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-23T06:55:46.000Z","updated_at":"2024-09-29T18:26:45.000Z","dependencies_parsed_at":"2024-06-21T19:08:39.862Z","dependency_job_id":"1a78b93e-df75-474c-9ddf-27fc30c5c734","html_url":"https://github.com/GEMISIS/discord-bot-cdk-construct","commit_stats":{"total_commits":28,"total_committers":3,"mean_commits":9.333333333333334,"dds":0.0714285714285714,"last_synced_commit":"0d262e2809a298a10af594a1033077d3a08e1b0a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GEMISIS%2Fdiscord-bot-cdk-construct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GEMISIS%2Fdiscord-bot-cdk-construct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GEMISIS%2Fdiscord-bot-cdk-construct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GEMISIS%2Fdiscord-bot-cdk-construct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GEMISIS","download_url":"https://codeload.github.com/GEMISIS/discord-bot-cdk-construct/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248225878,"owners_count":21068079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cdk","aws-cloudformation","aws-lambda","cdk","csharp","discord","discord-api","discord-bot","discord-js","discordapp","discordbot","discordjs","dotnet","java","nodejs","python","serverless","typescript"],"created_at":"2024-09-25T00:58:06.400Z","updated_at":"2025-04-10T13:35:07.971Z","avatar_url":"https://github.com/GEMISIS.png","language":"TypeScript","readme":"# discord-bot-cdk-construct\n\n![Version Badge](https://img.shields.io/github/package-json/v/GEMISIS/discord-bot-cdk-construct?color=blue\u0026logo=Discord) [![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)\n\nA CDK Construct for creating a serverless Discord bot. All you need to do is supply your code to handle the commands!\n\n# Architecture Overview\n\nThis is the architecture for how this project is laid out server-side. The tools used to create these diagrams are:\n\n- [Architecture Diagrams](https://app.diagrams.net)\n\nThe bot has a fairly straightforward setup:\n\n![The architecture diagram for the project.](https://github.com/GEMISIS/discord-bot-cdk-construct/blob/main/diagrams/architecture.png?raw=true)\n\nThe biggest confusion likely stems from the use of two Lambda functions instead of one. This is to ensure that the initial request can respond within Discord's 3 second time limit and return a proper response to the user.\n\n# Sample Usage\n\nThe usage is split into two parts: The [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/home.html) stack that will be used, and a \"commands\" script that actually handles responding. It's recommended that you are familiar with CDK first before diving into using this.\n\n## Handling Commands\n\nFor handling commands, you just need to provide a Lambda function for sending response to Discord's Web APIs. As an example of how this can be done:\n\n```typescript\nimport {Context, Callback} from 'aws-lambda';\nimport { IDiscordEventRequest, IDiscordResponseData, getDiscordSecrets, sendFollowupMessage } from 'discord-bot-cdk-construct';\n\nexport async function handler(event: IDiscordEventRequest, context: Context,\n  callback: Callback): Promise\u003cstring\u003e {\n\n  const discordSecret = await getDiscordSecrets();\n  const endpointInfo = {\n    authToken: discordSecret?.authToken,\n    applicationId: discordSecret?.applicationId\n  };\n  const response = {\n    tts: false,\n    content: 'Hello world!',\n    embeds: [],\n    allowedMentions: [],\n  };\n  if (event.jsonBody.token \u0026\u0026 await sendFollowupMessage(endpointInfo, event.jsonBody.token, response)) {\n    console.log('Responded successfully!');\n  } else {\n    console.log('Failed to send response!');\n  }\n  return '200';\n}\n```\n\n## Using the Construct\n\nTo create a stack to make use of the above script, you can create a stack like so:\n\n```typescript\nimport {Duration, Stack} from 'aws-cdk-lib';\nimport {Runtime} from 'aws-cdk-lib/aws-lambda';\nimport {NodejsFunction} from 'aws-cdk-lib/aws-lambda-nodejs';\nimport {DiscordBotConstruct} from 'discord-bot-cdk-construct';\nimport {Construct} from 'constructs';\nimport * as path from 'path';\n\n/**\n * Creates a sample Discord bot endpoint that can be used.\n */\nexport class SampleDiscordBotStack extends Stack {\n  /**\n   * The constructor for building the stack.\n   * @param {Construct} scope The Construct scope to create the stack in.\n   * @param {string} id The ID of the stack to use.\n   */\n  constructor(scope: Construct, id: string) {\n    super(scope, id);\n\n    // Create the Commands Lambda.\n    const discordCommandsLambda = new NodejsFunction(this, 'discord-commands-lambda', {\n      runtime: Runtime.NODEJS_18_X,\n      entry: path.join(__dirname, '../functions/DiscordCommands.ts'),\n      handler: 'handler',\n      timeout: Duration.seconds(60),\n    });\n\n    const discordBot = new DiscordBotConstruct(this, 'discord-bot-endpoint', {\n      commandsLambdaFunction: discordCommandsLambda,\n    });\n  }\n}\n```\n\nThis can of course then be used in your CDK application like so:\n\n```typescript\nimport { App } from 'aws-cdk-lib';\nimport { SampleDiscordBotStack } from './stacks/sample-discord-bot-stack';\n\nconst app = new App();\nconst startAPIStack = new SampleDiscordBotStack(app, 'SampleDiscordBotStack');\n```\n\n## Full Demo Project\n\nA full example project utilzing this construct can be found [here](https://github.com/RGB-Schemes/oculus-start-bot). Specifically, the [start-api-stack.ts](https://github.com/RGB-Schemes/oculus-start-bot/blob/mainline/src/stacks/start-api-stack.ts) file uses the construct, with [DiscordCommands.ts](https://github.com/RGB-Schemes/oculus-start-bot/blob/mainline/src/functions/DiscordCommands.ts) being the commands file (like shown above).\n\n## Packaging with JSII\n\nIn order to package everything with JSII, ensure you have the following installed:\n\n- Python3\n- Open JDK\n- Maven\n\nSee [JSII's Prerequisites Documentation](https://aws.github.io/jsii/user-guides/lib-author/) for more information.\n\n# Useful commands\n\n- `npm run build`   compile typescript to js\n- `npm run watch`   watch for changes and compile\n- `npm run test`    perform the jest unit tests\n- `npm run lint`       perform a lint check across the code\n- `npm run fix-lint`   fix any lint issues automatically where possible\n- `npm run package`   package all of the bindings for distribution\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgemisis%2Fdiscord-bot-cdk-construct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgemisis%2Fdiscord-bot-cdk-construct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgemisis%2Fdiscord-bot-cdk-construct/lists"}