{"id":15021723,"url":"https://github.com/davipccunha/discordjs-helper","last_synced_at":"2025-10-04T00:24:39.084Z","repository":{"id":255437872,"uuid":"847150575","full_name":"davipccunha/discordjs-helper","owner":"davipccunha","description":"A package that contains useful functions to complement discord.js library","archived":false,"fork":false,"pushed_at":"2024-09-12T15:43:44.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T05:25:08.461Z","etag":null,"topics":["bot","discord","discordjs","helper"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davipccunha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-25T02:05:00.000Z","updated_at":"2024-10-27T22:50:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"a217c17a-ebdd-4bd8-94af-a83fd075098d","html_url":"https://github.com/davipccunha/discordjs-helper","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"feddb7bee99b470853f5ec5c0e6ef80a52aea1b0"},"previous_names":["davipccunha/discordjs-helper"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davipccunha%2Fdiscordjs-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davipccunha%2Fdiscordjs-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davipccunha%2Fdiscordjs-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davipccunha%2Fdiscordjs-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davipccunha","download_url":"https://codeload.github.com/davipccunha/discordjs-helper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238909295,"owners_count":19550837,"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","discordjs","helper"],"created_at":"2024-09-24T19:56:56.904Z","updated_at":"2025-10-04T00:24:39.078Z","avatar_url":"https://github.com/davipccunha.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/davipccunha"],"categories":[],"sub_categories":[],"readme":"\u003cp align=”center”\u003e\n    \u003cimg alt=\"NPM Downloads\" src=\"https://img.shields.io/npm/dy/%40davipccunha%2Fdiscordjs-helper\"\u003e\n\u003c/p\u003e\n\n# About\n## Easily create interactions with type safety\ndiscordjs-helper allows you to more easily create and register interactions to the Discord API. It ensures type safety and avoid runtime errors. This package contains:\n\n- Interfaces to implement and consistently define your interactions\n- Decorators to help with common verifications such as users' permissions\n- Extensions to discordjs' classes like BaseInteraction#replyOrFollowUp()\n\n\u003e **A complete documentation is available at https://davipccunha.github.io/discordjs-helper/docs/intro**\n\n\u003c/br\u003e\n\n# Installation\n### Node.js and npm required!\nRun into your project's terminal:\n```\nnpm install @davipccunha/discordjs-helper\n```\n\u003c/br\u003e\n\n# Examples\n\n## Creating a new slash command\n```typescript\nimport { CustomChatInputCommand, ExtendedClient, RegisterChatInputCommand, RequireMemberPermission } from \"@davipccunha/discordjs-helper\";\nimport { ApplicationCommandType, ChatInputCommandInteraction, PermissionFlagsBits } from \"discord.js\";\n\n@RegisterChatInputCommand(\"ping\", \"Ping the bot!\")\n@RequireMemberPermission(PermissionFlagsBits.Administrator)\nexport class PingCommand implements CustomChatInputCommand {\n    name!: string;\n    type!: ApplicationCommandType.ChatInput;\n    description!: string;\n    defaultPermission!: boolean;\n\n    async execute(interaction: ChatInputCommandInteraction, client: ExtendedClient): Promise\u003cvoid\u003e {\n        await interaction.reply('Pong!').catch(console.error);\n    }\n}\n```\n\nThe class above defines a chat input command. It contains the information to create the command and a method `execute()`, that is run when a command interaction with the same name as the class' attribute `name` is created on Discord.\n\n## Registering slash commands\nCommands should be either registered using the `ExtendedClient#registerCommands()` method or by decorating its class with `@Register...Command(name)` and then sent to Discord API using `ExtendedClient#loadCommands()`. Due to how Node.js loads the modules, a module that contains a command class decorated with @Register...Command must be imported in some point of your program\n\n```typescript\nimport path from 'path';\nimport { pathToFileURL } from 'url';\nimport { ExtendedClient, recursiveFiles } from \"@davipccunha/discordjs-helper\";\n\nconst client = new ExtendedClient(\"TOKEN GOES HERE\");\n\n// This is necessary due to how Node.js loads modules\nawait registerInteractions();\n\n// This should be called after registering the commands\n// This function caches the registered interactions, starts the bot and starts listening for interactions being created\nclient.start(true);\n\n// This function registers the cached commands to the guilds passed as parameters (it registers to all if no parameter is passed)\nclient.loadCommands(\"GUILD ID 1\", \"GUILD ID 2\", ...);\n\n// This code gets all files inside the dist/interactions folder and imports them so they are loaded and interactions decorated with @Register... are correctly registered\nasync function registerInteractions() {\n    const interactions = await recursiveFiles(\"dist/interactions\");\n    for (const interaction of interactions) {\n        const fileName = interaction.replaceAll('\\\\', '/');\n        const absolutePath = path.resolve(fileName);\n\n        const fileUrl = pathToFileURL(absolutePath).href;\n\n        await import(fileUrl);\n    }\n};\n```\n\n### Together, the two code snippets above is all there is to get your first slash command working.\nThe example provided on how to register the commands is a simple way of loading all modules, regardless of how many interactions you have, instead of having to instantiate each one of them and pass them as parameter to the register methods\n\u003cbr\u003e\n\n# Reminders\nTo use decorators, you must enable them in your .tsconfig file `{\"compilerOptions\": {\"experimentalDecorators\": true}}`.  \nFor interactions decorated with @Register..., the module in which they are defined must be imported somewhere in the main program due to how Node.js loads modules\n\nYou can always register all your interactions using one of the following methods from ExtendedClient: \n- registerCommands()\n- registerButtons()\n- registerSelectMenus()\n- registerModals()\n\nand passing false as argument to the ExtendedClient#start() method (to disable auto-register)\n\nThen, the package handles the rest, including when interactions are created\n\n# Found a problem?\nPlease let me know of any problems found by opening an issue at [GitHub issue](https://github.com/davipccunha/discordjs-helper/issues). If you have a suggestion or just want to contact me, please send an email to davipccunha@gmail.com\n\n# Donations\nIf you are feeling generous or would like to support this and other future open-source projects, you can donate at my [Buy me a coffee](https://www.buymeacoffee.com/davipccunha) page","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavipccunha%2Fdiscordjs-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavipccunha%2Fdiscordjs-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavipccunha%2Fdiscordjs-helper/lists"}