{"id":15554920,"url":"https://github.com/kylar101/discord-controller","last_synced_at":"2026-01-24T18:31:24.666Z","repository":{"id":40709616,"uuid":"278538894","full_name":"Kylar101/discord-controller","owner":"Kylar101","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-18T20:50:40.000Z","size":208,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T21:47:48.161Z","etag":null,"topics":["bot","discord"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/discord-controller","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/Kylar101.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":"2020-07-10T04:35:48.000Z","updated_at":"2024-03-28T04:39:28.000Z","dependencies_parsed_at":"2024-03-18T06:26:26.238Z","dependency_job_id":"1d0056ec-3426-4282-9570-bb7cf4143a5d","html_url":"https://github.com/Kylar101/discord-controller","commit_stats":{"total_commits":99,"total_committers":4,"mean_commits":24.75,"dds":"0.21212121212121215","last_synced_commit":"58f0ad664142a43cf4a7a1502f22072efb9ceb2d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kylar101%2Fdiscord-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kylar101%2Fdiscord-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kylar101%2Fdiscord-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kylar101%2Fdiscord-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kylar101","download_url":"https://codeload.github.com/Kylar101/discord-controller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276473,"owners_count":22043869,"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":["bot","discord"],"created_at":"2024-10-02T15:04:43.508Z","updated_at":"2026-01-24T18:31:24.631Z","avatar_url":"https://github.com/Kylar101.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discord Controller\n\u003e A discord bot framework with inbuilt dependency injection\n\n## Installation\n\n1. Install module and the discord sdk\n\n    `npm install discord-controller discord.js`\n\n2. `reflect-metadata` shim is required\n\n    `npm install reflect-metadata`\n\n   and make sure to import it before using discord-controller\n\n3. Its important to set the following options in the `tsconfig.json` file of your project\n\n    ```\n    {\n        \"emitDecoratorMetadata\": true,\n        \"experimentalDecorators\": true\n    }\n    ```\n\n## Example of useage\n\n1. Register a new bot with [discord](https://discordjs.guide/preparations/setting-up-a-bot-application.html#creating-your-bot), add it to your server and copy your auth token\n\n2. Create a file `MyCommand.ts`\n\n    ```typescript\n    import { Action, Command, Interaction } from 'discord-controller';\n\n    @Command({ description: 'This is the description' })\n    export class MyCommand extends Action {\n      constructor() {\n        super();\n      }\n    \n      async run(message: Interaction) {\n        await message.reply('This command will reply to the user');\n      }\n    }\n    ```\n\n    this class will register a command with the bot\n\n3. Create a file `bot.ts`\n    ```typescript\n    import { createServer } from 'discord-controller';\n    import { MyCommand } from './MyCommand';\n    \n    (async () =\u003e {\n      try {\n        const bot = await createServer({\n          permissions: [],\n          token: 'TOKEN',\n          guildId: 'GUILD_ID',\n          clientId: 'CLIENT_ID',\n          commands: [\n            MyCommand,\n          ],\n        });\n        bot.start();\n      } catch (e) {\n        console.log('Unable to start bot');\n      }\n    })();\n\n    ```\n\n4. Run your bot and type `/mycommand` in your discord server. The bot will respond with `\"This command will reply to the user\"`\n\n## More Examples\n\n### Sub Commands\n\nIf you are designing a command that has options, you can use `@SubCommand` in addition to `@Command` to add flags to your command.\n\n```typescript\nimport { Action, Command, Interaction, SubCommand, Flag, FlagType } from 'discord-controller';\n\n@Command({ description: 'This is the description' })\nexport class Test extends Action {\n  constructor() {\n    super();\n  }\n\n  async run(\n    message: Interaction\n  ): Promise\u003cvoid\u003e {\n    await message.reply('This will be send from the base command');\n  }\n\n  @SubCommand({ description: 'This is the description' })\n  async subCommand(\n    interaction: Interaction\n  ) {\n    await interaction.reply('This will be sent from the subcommand');\n  }\n}\n```\n\nThis will create 2 commands for `MyCommand`, a `default` command and a `subCommand` command. Accesable like `/mycommand default` and `/mycommand subcommand`\n\n`/mycommand default` will respond with `\"This will be sent from the base command\"` and `/mycommand subcommand` will respond with `\"This will be sent from the subcommand\"`\n\n### Dependency Injection\n\n`discord-controller` has inbuilt dependency injection that will work automatically when using the `@Service` decorator\n\n```typescript\nimport { Command, Interaction, Service, Action } from 'discord-controller';\n\n@Service()\nexport class MyService {\n    myFunction() {\n        return 'this is from a service';\n    }\n}\n\n@Command({ description: 'description' })\nexport class MyCommand extends Action {\n    constructor(private service: MyService) {\n        super();\n    }\n\n    run(message: Interaction) {\n        message.channel.send(this.service.myFunction());\n    }\n}\n```\n\n### Authorisation\n\nIf you are designing a command that needs to be restricted to users with a particular role, you can use `@Authorized` in addition to `@Command` to restrict access.\n\n```typescript\nimport { Command, Authorized, Action } from 'discord-controller';\nimport { Message } from 'discord.js'\n\n@Authorized('AllowedRole')\n@Command({ description: 'description' })\nexport class MyCommand extends Action {\n  constructor() {\n    super();\n  }\n\n  run(message: Interaction) {\n    message.channel.send('This command can be used by members who have the `AllowedRole` role');\n  }\n}\n```\n\n### Listeners\n\nIf you are to monitor for a certain action being performed, you can use `@Listen` and pass in the event that you wish to monitor\n\n```typescript\nimport { ClientEvents, Events } from 'discord.js';\nimport { Listen, Listener, DiscordEvents } from 'discord-controller';\n\n@Listen(Events.MessageCreate)\nexport class TestListener implements Listener\u003cDiscordEvents.Message\u003e {\n  async listen(parameters: ClientEvents[Events.MessageCreate]) {\n    const [message] = parameters;\n    return message.content.includes('hello');\n  }\n\n  run(parameters: ClientEvents[Events.MessageCreate]) {\n    const [message] = parameters;\n    message.channel.send('someone sent a greeting');\n  }\n}\n```\n\n\u003e NOTE: If you find that the listener is not working, check that you have added the required permissions during start up\n\nTo view supported events visit the [discord.js documentation](https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-channelCreate)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylar101%2Fdiscord-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkylar101%2Fdiscord-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylar101%2Fdiscord-controller/lists"}