From 743f80b8a626bfdbc9d7fd604e80cc96a85f05d3 Mon Sep 17 00:00:00 2001
From: Federico <38290480+FedeIlLeone@users.noreply.github.com>
Date: Fri, 15 Sep 2023 12:29:14 +0200
Subject: [PATCH] feat: doc slash commands
---
docs/plugins/injecting.mdx | 58 +++++++++++++++++++++++++++++++-
src/components/APIReferences.tsx | 1 +
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/docs/plugins/injecting.mdx b/docs/plugins/injecting.mdx
index b1a6106..ad6f2ba 100644
--- a/docs/plugins/injecting.mdx
+++ b/docs/plugins/injecting.mdx
@@ -106,6 +106,7 @@ The injector class has an `uninjectAll` method which will remove all injections
```ts
import { Injector } from "replugged";
+
const injector = new Injector();
export function start() {
@@ -130,7 +131,7 @@ buttons that are shown in the top right corner when you hover over a message, li
reply, etc. The button order cannot be controlled.
```ts
-import { Injector, webpack } from "replugged";
+import { Injector } from "replugged";
const injector = new Injector();
@@ -211,3 +212,58 @@ export function stop(): void {
More examples can be found
[here](https://github.com/asportnoy/context-menu-demo/blob/main/src/index.tsx).
+
+### Slash Commands
+
+You can use the `registerSlashCommand` util to register a custom slash command under the Replugged
+command section. In the following example we are registering a slash command which sends a normal
+message or an , based on the value of the option.
+
+```tsx
+import { Injector, types } from "replugged";
+const { ApplicationCommandOptionType } = types;
+
+const injector = new Injector();
+
+export function start(): void {
+ injector.utils.registerSlashCommand({
+ name: "my-command",
+ description: "Helpful command description",
+ options: [
+ {
+ name: "my-option",
+ description: "Very cool option description",
+ type: ApplicationCommandOptionType.Boolean,
+ required: true,
+ },
+ ],
+ executor: (interaction) => {
+ // Get the value of the option
+ const sendEmbed = interaction.getValue("my-option");
+
+ if (myOption) {
+ return {
+ // Whether to send an ephemeral message
+ send: false,
+ result: "This is a message",
+ };
+ } else {
+ return {
+ send: false,
+ embeds: [
+ {
+ color: 0x5865f2,
+ title: "Embed title",
+ description: "Embed description",
+ },
+ ],
+ };
+ }
+ },
+ });
+}
+
+export function stop(): void {
+ injector.uninjectAll();
+}
+```
diff --git a/src/components/APIReferences.tsx b/src/components/APIReferences.tsx
index 3d5f313..8891c0f 100644
--- a/src/components/APIReferences.tsx
+++ b/src/components/APIReferences.tsx
@@ -7,6 +7,7 @@ const DiscordAPIDocs = (props): JSX.Element => {
export default {
Channel: () => ,
+ Embed: () => ,
Emoji: () => ,
Guild: () => ,
GuildMember: () => (