mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import {
|
|
ApplicationCommandOptionChoiceData,
|
|
AutocompleteInteraction,
|
|
CacheType,
|
|
} from 'discord.js';
|
|
import { REGION_NAMES } from '../../constants/regions';
|
|
import listPlayers from '../blitz/listPlayers';
|
|
|
|
export default async function autocompleteUsername(
|
|
interaction: AutocompleteInteraction<CacheType>,
|
|
) {
|
|
const focusedOption = interaction.options.getFocused(true);
|
|
if (focusedOption.name !== 'username') return;
|
|
const players = await listPlayers(focusedOption.value);
|
|
|
|
try {
|
|
await interaction.respond(
|
|
players
|
|
? players.map(
|
|
(player) =>
|
|
({
|
|
name: `${player.nickname} (${REGION_NAMES[player.server]})`,
|
|
value: `${player.server}/${player.account_id}`,
|
|
}) satisfies ApplicationCommandOptionChoiceData<string>,
|
|
)
|
|
: [],
|
|
);
|
|
|
|
console.log(`Username autocomplete for ${focusedOption.value}`);
|
|
} catch (error) {
|
|
console.warn(
|
|
`Failed to autocomplete username for ${focusedOption.value} in time`,
|
|
);
|
|
}
|
|
}
|