diff --git a/src/content/docs/v3/api/functions/Services.md b/src/content/docs/v3/api/functions/Services.md index fc4d07dff..da11a1808 100644 --- a/src/content/docs/v3/api/functions/Services.md +++ b/src/content/docs/v3/api/functions/Services.md @@ -24,7 +24,7 @@ array of dependencies, in the same order of keys provided ## Since 3.0.0 -The plural version of [Service](../../../../../../v3/api/functions/service) +The plural version of [Service](../../../../../../../../v3/api/functions/service) ## Source diff --git a/src/content/docs/v3/api/functions/discordEvent.md b/src/content/docs/v3/api/functions/discordEvent.md index 189b9c942..fd9790fe8 100644 --- a/src/content/docs/v3/api/functions/discordEvent.md +++ b/src/content/docs/v3/api/functions/discordEvent.md @@ -8,7 +8,7 @@ title: "discordEvent" > **discordEvent**\<`T`\>(`mod`): [`EventModule`](/v3/api/type-aliases/eventmodule/) Create event modules from discord.js client events, -This is an [eventModule](../../../../../../v3/api/functions/eventmodule) for discord events, +This is an [eventModule](../../../../../../../../v3/api/functions/eventmodule) for discord events, where typings can be very bad. ## Type parameters diff --git a/src/content/docs/v3/api/type-aliases/SernOptionsData.md b/src/content/docs/v3/api/type-aliases/SernOptionsData.md index a38e7fe9d..efd12c0a1 100644 --- a/src/content/docs/v3/api/type-aliases/SernOptionsData.md +++ b/src/content/docs/v3/api/type-aliases/SernOptionsData.md @@ -7,7 +7,7 @@ title: "SernOptionsData" > **SernOptionsData**: [`SernSubCommandData`](/v3/api/interfaces/sernsubcommanddata/) \| [`SernSubCommandGroupData`](/v3/api/interfaces/sernsubcommandgroupdata/) \| `APIApplicationCommandBasicOption` \| [`SernAutocompleteData`](/v3/api/interfaces/sernautocompletedata/) -Type that replaces autocomplete with [SernAutocompleteData](../../../../../../v3/api/interfaces/sernautocompletedata) +Type that replaces autocomplete with [SernAutocompleteData](../../../../../../../../v3/api/interfaces/sernautocompletedata) ## Source diff --git a/src/content/docs/v4/api/functions/Services.md b/src/content/docs/v4/api/functions/Services.md index c95f4f844..3e59fcbf3 100644 --- a/src/content/docs/v4/api/functions/Services.md +++ b/src/content/docs/v4/api/functions/Services.md @@ -24,7 +24,7 @@ array of dependencies, in the same order of keys provided ## Since 3.0.0 -The plural version of [Service](../../../../../../v4/api/functions/service) +The plural version of [Service](../../../../../../../../v4/api/functions/service) ## Source diff --git a/src/content/docs/v4/api/functions/discordEvent.md b/src/content/docs/v4/api/functions/discordEvent.md index ff33cec6c..c92407d64 100644 --- a/src/content/docs/v4/api/functions/discordEvent.md +++ b/src/content/docs/v4/api/functions/discordEvent.md @@ -8,7 +8,7 @@ title: "discordEvent" > **discordEvent**\<`T`\>(`mod`): `Module` Create event modules from discord.js client events, -This is an [eventModule](../../../../../../v4/api/functions/eventmodule) for discord events, +This is an [eventModule](../../../../../../../../v4/api/functions/eventmodule) for discord events, where typings can be very bad. ## Type parameters diff --git a/src/content/docs/v4/api/type-aliases/SernOptionsData.md b/src/content/docs/v4/api/type-aliases/SernOptionsData.md index 48eedd7cc..b166b44e0 100644 --- a/src/content/docs/v4/api/type-aliases/SernOptionsData.md +++ b/src/content/docs/v4/api/type-aliases/SernOptionsData.md @@ -7,7 +7,7 @@ title: "SernOptionsData" > **SernOptionsData**: [`SernSubCommandData`](/v4/api/interfaces/sernsubcommanddata/) \| [`SernSubCommandGroupData`](/v4/api/interfaces/sernsubcommandgroupdata/) \| `APIApplicationCommandBasicOption` \| [`SernAutocompleteData`](/v4/api/interfaces/sernautocompletedata/) -Type that replaces autocomplete with [SernAutocompleteData](../../../../../../v4/api/interfaces/sernautocompletedata) +Type that replaces autocomplete with [SernAutocompleteData](../../../../../../../../v4/api/interfaces/sernautocompletedata) ## Source diff --git a/src/content/docs/v4/reference/autocomplete.mdx b/src/content/docs/v4/reference/autocomplete.mdx new file mode 100644 index 000000000..9e99b01b1 --- /dev/null +++ b/src/content/docs/v4/reference/autocomplete.mdx @@ -0,0 +1,83 @@ +--- +title: Autocomplete +description: Implementing autocomplete in your commands +sidebar: + order: 7 +--- + +Autocomplete is a special interaction which can happen on multiple options can be suggested for a single command. +We've implemented this functionality using a simple tree search algorithm within a nested options tree. + +## Example +In this example, the option `list` will autocomplete with the cheeses `gouda`, `parmesan`, and `harvarti`. + +```ts title="src/commands/cheese.ts" {13-22} +export default commandModule({ + type: CommandType.Slash, + description: "show me cheese", + options: [ + { + name: "list", + type: ApplicationCommandOptionType.String, + description: "pick a cheese to show", + required: true, + autocomplete: true, + command: { + execute: (ctx) => { + // focus can be used to refine the options + const focus = ctx.options.getFocused(); + ctx.respond( + ["gouda", "parmesan", "harvarti"].map((cheese) => ({ + name: cheese, + value: cheese, + })), + ); + }, + }, + }, + ], + execute: (ctx, [, args]) => { + const cheese = args.getString("list", true); + ctx.reply("selected cheese"); + }, +}); +``` + +## Using Focus + +The `focus` object refines the options. For example, if the user types `g`, the focus object will be `g`. +We can filter cheeses based on the focus object, and return only the cheeses that start with the focus object. +You can do a lot more with the focus object, such as performing API calls, or implementing a fuzzy search. + +```ts title="src/commands/cheese.ts" {13-23} +export default commandModule({ + type: CommandType.Slash, + description: "show me cheese", + options: [ + { + name: "list", + type: ApplicationCommandOptionType.String, + description: "pick a cheese to show", + required: true, + autocomplete: true, + command: { + onEvent: [], + execute: (ctx) => { + const focus = ctx.options.getFocused(); + ctx.respond ["gouda", "parmesan", "harvarti"] + .filter((cheese) => cheese.startsWith(focus)) + .map((cheese) => ({ name: cheese, value: cheese }))); + }, + }, + }, + ], + execute: (ctx) => { + const cheese = ctx.options.getString("list", true); + ctx.reply("selected cheese"); + }, +}); +``` + +:::tip +sern will handle autocomplete interactions at arbitrary depths and subcommand levels. +::: diff --git a/src/content/docs/v4/reference/conclusion.mdx b/src/content/docs/v4/reference/conclusion.mdx new file mode 100644 index 000000000..1c700832a --- /dev/null +++ b/src/content/docs/v4/reference/conclusion.mdx @@ -0,0 +1,14 @@ +--- +title: Conclusion +description: Thank you for reading the sern guide +sidebar: + order: 8 +--- + +If you reached this far, thank you for reading! + +We hope you have learned the necessities you need to create a bot with the sern framework. + +If you have any other questions, bugs, feature requests, concerns, please join our [community server](https://sern.dev/discord), and we'll be glad to answer your questions! + +![paper logo](~/assets/blog/paper-logo.png) diff --git a/src/content/docs/v4/tools/localizer.mdx b/src/content/docs/v4/tools/localizer.mdx index eda90fa6f..2b338bc07 100644 --- a/src/content/docs/v4/tools/localizer.mdx +++ b/src/content/docs/v4/tools/localizer.mdx @@ -46,7 +46,7 @@ import { Tabs, TabItem } from "@astrojs/starlight/components"; ```json title=~/assets/locals/en-US.json { "salute": { - "hello": "hello" + "hello": "hola" } } ```