-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsampleAutocompleter.ts
36 lines (29 loc) · 1.15 KB
/
sampleAutocompleter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Autocompleter } from "../interactions/interactionClasses";
import { AutocompleteInteraction } from "discord.js";
class CountryAutocompleter extends Autocompleter {
constructor() {
super("country"); // command which this autocompleter is for
}
async execute(interaction: AutocompleteInteraction): Promise<void> {
// your options
const country = ["Finland", "Sweden", "Norway"];
// for example filter for options which start with the user input
let filterdoptions = country.filter((c) =>
c
// to make sure capitalisaion doesnt matter, make every option to lower case
.toLowerCase()
.startsWith(
// the same with the user input
interaction.options.getFocused().toLowerCase() as string
)
);
// if the filterd options are more than 25 remove everything after the 25th option
// because discord only allows 25 autocomplete results
if (filterdoptions.length > 25) filterdoptions = filterdoptions.slice(0, 25);
// map filtered options
const map = filterdoptions.map((c) => ({ name: c, value: c }));
// send map back to the user
await interaction.respond(map);
}
}
export default new CountryAutocompleter();