{"id":15641605,"url":"https://github.com/alii/discord-jsx","last_synced_at":"2025-08-02T02:12:12.515Z","repository":{"id":45234011,"uuid":"307538501","full_name":"alii/discord-jsx","owner":"alii","description":"💬 An experimental way to write Discord bots with JSX for Node.","archived":false,"fork":false,"pushed_at":"2021-12-29T13:59:17.000Z","size":72,"stargazers_count":80,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-17T18:16:40.074Z","etag":null,"topics":["discord","discord-js","discord-jsx","jsx","react"],"latest_commit_sha":null,"homepage":"https://alistair.sh","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/alii.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}},"created_at":"2020-10-27T00:09:53.000Z","updated_at":"2025-02-28T15:25:03.000Z","dependencies_parsed_at":"2022-08-04T13:00:31.424Z","dependency_job_id":null,"html_url":"https://github.com/alii/discord-jsx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alii/discord-jsx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fdiscord-jsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fdiscord-jsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fdiscord-jsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fdiscord-jsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alii","download_url":"https://codeload.github.com/alii/discord-jsx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fdiscord-jsx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268326739,"owners_count":24232496,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["discord","discord-js","discord-jsx","jsx","react"],"created_at":"2024-10-03T11:43:34.149Z","updated_at":"2025-08-02T02:12:12.448Z","avatar_url":"https://github.com/alii.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# `discord-jsx`\n\n### Installation\n\n```\nyarn add discord-jsx\n```\n\n### Usage\n\n##### View the example in [examples](examples/index.tsx)\n\n## API\n\n## Components\n\n### `\u003cClient /\u003e`\n\n| _prop_      | prefix                | onError?                    |\n| ----------- | --------------------- | --------------------------- |\n| _type_      | string                | `(error: Error) =\u003e unknown` |\n| Description | The prefix of the bot | An error handler            |\n\nThis is the most fundamental part of any `discord-jsx` application. It is the internal `Provider` for the discord.js `Client` under the hood, as well as prefix among other things.\n\n### `\u003cToken token={string} /\u003e`\n\n| _prop_      | token         | onReady                       | onLogin?                      |\n| ----------- | ------------- | ----------------------------- | ----------------------------- |\n| _type_      | string        | `(client: Client) =\u003e unknown` | `(client: Client) =\u003e unknown` |\n| Description | The bot token | Ready event shorthand         | Login event shorthand         |\n\nThis component will run `client.login()` under the hood, and is the starting point for any `discord-jsx` client.\n\n### `\u003cCommand /\u003e`\n\n| _prop_      | name                    | description                               | inhibitors?                      | handler?                                           | children?                      |\n| ----------- | ----------------------- | ----------------------------------------- | -------------------------------- | -------------------------------------------------- | ------------------------------ |\n| _type_      | string                  | string                                    | `Inhibitor[]`                    | `(message: Message, ...args: string[]) =\u003e unknown` | Read below                     |\n| Description | The name of the command | The description of what this command does | Optional inhibitors (Read below) | Optional handler function (Read below)             | Optional children (Read below) |\n\nThe `Command` component is very versatile when not using a `handler` function prop. It supports three main types of children. Text (string or number), a Shortcut (we'll come on to that later), or a custom function that takes 0-2 arguments.\n\nFor instance, we can pass regular text as a simple reply. E.g.\n\n```tsx\n\u003cCommand name={\"example\"} description={\"This is an example command\"}\u003e\n  This would be the example reply.\n\u003c/Command\u003e\n```\n\nHowever, we can do much more with Shortcuts. As the name implies, these are shorter ways to template a message. `discord-jsx` has a few built in. Currently, they are `author` and `channelName`. You can use shortcuts in a handlebars-style syntax. E.g.\n\n```tsx\n\u003cCommand\n  name={\"example\"}\n  description={\"This is an example command using shortcuts\"}\n\u003e\n  Hello, {{ author }}. You sent a message in {{ channelName }}.\n\u003c/Command\u003e\n```\n\nUnder the hood, these are actually valid JavaScript objects, and we just call the first property. A shortcut is simply a function that takes a `Message` as the first argument and always returns a string. Because of this, it's easy to build your own and reuse them as you please.\n\nSecondly, `Command` also accepts a function that takes 0-2 argument. Similar to a `Shortcut` however this time, they can be async. This allows for database calls etc to be executed. E.g.\n\n```tsx\n// An example function\nasync function getFavouriteFood(discordId: string): Promise\u003cstring\u003e {\n  const user = await database.getUserByDiscord(discordId);\n  return user.favouriteFood;\n}\n\n\u003cCommand\n  name={\"food\"}\n  description={\"This is an example command using inline functions\"}\n\u003e\n  Hello {{ author }}. Your favourite food is{\" \"}\n  {(msg) =\u003e getFavouriteFood(msg.author.id)}.\n\u003c/Command\u003e;\n```\n\nAnd an example using the second argument (message args)\n\n```tsx\n\u003cCommand name={\"say\"} description={\"Repeats what you say\"}\u003e\n  {(msg, ...args) =\u003e arg.join(\" \")}\n\u003c/Command\u003e\n```\n\n### `\u003cEvent /\u003e`\n\n| _prop_      | event                                                                          | handler                                                                  |\n| ----------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |\n| _type_      | [`keyof ClientEvents`](https://discord.js.org/#/docs/main/stable/class/Client) | Function that accepts the params referenced in the list of client events |\n| Description | The event name                                                                 | The handler for this event                                               |\n\nThis is a component for listening to custom Discord.js Client events. It's fairly self-explanatory. Here's a couple examples:\n\n```tsx\n\u003cEvent event={\"message\"} handler={message =\u003e console.log(message.content)} /\u003e\n\u003cEvent event={\"guildCreate\"} handler={guild =\u003e console.log(`Client joined ${guild.name}`)} /\u003e\n```\n\n## Hooks\n\nIf you want to use the client in your own hook, you can use `useClientContext` which returns [`ClientContext`](./src/context.ts) – an object containing the `Client` and `prefix`.\n\nFor example:\n\n```tsx\n// Custom hook to check if a string starts with the current prefix\nfunction useIsCommand(content: string): boolean {\n  const context = useClientContext();\n  return content.startsWith(context.prefix);\n}\n```\n\n## Inhibitors\n\nStolen from [cookiecord](https://github.com/cookiecord/cookiecord), inhibitors are a way of preventing a command from executing when a specific condition isn't met.\n\nThey are very easy to make, and we provide a couple from the constant `CommonInhibitors`. You use them in a `\u003cCommand /\u003e` component, documented above.\n\nFor example:\n\n```tsx\n// A command that will only run in a guild\n\u003cCommand inhibitors={[CommonInhibitors.guildsOnly]} name={\"guildsonly\"} description={\"A command that will run in a guild only\"} handler={/*...*/} /\u003e\n\u003cCommand inhibitors={[CommonInhibitors.noBots]} name={\"nobots\"} description={\"A command that cannot be triggered by bots\"} handler={/*...*/} /\u003e\n```\n\nTo build an inhibitor, you can import the `Inhibitor` type. Inhibitors stop execution just by throwing a regular error. The error gets caught, and the message is echoed to the channel where the inhibition rose.\n\n##### This project is very experimental, don't use it in production... please.....\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falii%2Fdiscord-jsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falii%2Fdiscord-jsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falii%2Fdiscord-jsx/lists"}