Skip to content

Commit

Permalink
feat: doc slash commands
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeIlLeone committed Sep 15, 2023
1 parent fc4d2f4 commit 743f80b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
58 changes: 57 additions & 1 deletion docs/plugins/injecting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();

Expand Down Expand Up @@ -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 <APIReferences.Embed />, 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");

Check warning on line 242 in docs/plugins/injecting.mdx

View workflow job for this annotation

GitHub Actions / Run ESLint

'sendEmbed' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 242 in docs/plugins/injecting.mdx

View workflow job for this annotation

GitHub Actions / Run ESLint

'sendEmbed' is assigned a value but never used. Allowed unused vars must match /^_/u

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();
}
```
1 change: 1 addition & 0 deletions src/components/APIReferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const DiscordAPIDocs = (props): JSX.Element => {

export default {
Channel: () => <DiscordAPIDocs name="Channel" link="channel#channel-object-channel-structure" />,
Embed: () => <DiscordAPIDocs name="Embed" link="channel#embed-object-embed-structure" />,
Emoji: () => <DiscordAPIDocs name="Emoji" link="emoji#emoji-object-emoji-structure" />,
Guild: () => <DiscordAPIDocs name="Guild" link="guild#guild-object-guild-structure" />,
GuildMember: () => (
Expand Down

0 comments on commit 743f80b

Please sign in to comment.