2023-05-14 17:13:42 +00:00
|
|
|
import {
|
|
|
|
|
ApplicationCommandOptionChoiceData,
|
|
|
|
|
AutocompleteInteraction,
|
|
|
|
|
CacheType,
|
|
|
|
|
} from 'discord.js';
|
2023-07-15 18:44:20 +00:00
|
|
|
import { REGION_NAMES } from '../../constants/regions';
|
2023-10-14 11:15:42 -05:00
|
|
|
import searchPlayersAcrossRegions from '../../core/blitz/searchPlayersAcrossRegions';
|
2023-05-14 17:13:42 +00:00
|
|
|
|
2023-06-27 02:22:28 +00:00
|
|
|
export default async function autocompleteUsername(
|
2023-05-14 17:13:42 +00:00
|
|
|
interaction: AutocompleteInteraction<CacheType>,
|
|
|
|
|
) {
|
|
|
|
|
const focusedOption = interaction.options.getFocused(true);
|
|
|
|
|
if (focusedOption.name !== 'username') return;
|
2023-10-14 11:15:42 -05:00
|
|
|
const players = await searchPlayersAcrossRegions(focusedOption.value);
|
2023-05-14 17:13:42 +00:00
|
|
|
|
2023-05-28 16:56:15 +00:00
|
|
|
try {
|
|
|
|
|
await interaction.respond(
|
|
|
|
|
players
|
|
|
|
|
? players.map(
|
|
|
|
|
(player) =>
|
|
|
|
|
({
|
2023-09-18 23:05:19 +00:00
|
|
|
name: `${player.nickname} (${REGION_NAMES[player.region]})`,
|
|
|
|
|
value: `${player.region}/${player.account_id}`,
|
2023-07-11 19:54:57 +00:00
|
|
|
}) satisfies ApplicationCommandOptionChoiceData<string>,
|
2023-05-28 16:56:15 +00:00
|
|
|
)
|
|
|
|
|
: [],
|
|
|
|
|
);
|
2023-10-11 20:18:51 -05:00
|
|
|
} catch (error) {}
|
2023-05-14 17:13:42 +00:00
|
|
|
}
|