add more to reference

This commit is contained in:
Jacob Nguyen
2024-06-11 10:55:31 -05:00
parent 5678001351
commit 27d3feab67
9 changed files with 104 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.
:::

View File

@@ -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)

View File

@@ -46,7 +46,7 @@ import { Tabs, TabItem } from "@astrojs/starlight/components";
```json title=~/assets/locals/en-US.json
{
"salute": {
"hello": "hello"
"hello": "hola"
}
}
```