fix: use API types for options

prepare for the MOST amazing thing in the world
This commit is contained in:
Jozef Steinhübl 2023-08-24 11:14:12 +02:00
parent 97638dc032
commit beecd9a7a6
3 changed files with 46 additions and 4 deletions

21
src/commands/docs.ts Normal file
View file

@ -0,0 +1,21 @@
import { SlashCommandStringOption } from "discord.js";
import { defineCommand } from "../loaders/commands";
import { AutocompleteContext } from "../structs/context/AutocompleteContext";
import { Option } from "../structs/Command";
defineCommand({
name: "docs",
options: [
{
...new SlashCommandStringOption()
.setName("query")
.setRequired(true)
.setAutocomplete(true)
.setDescription("Select query")
.toJSON(),
run: (_: Option, context: AutocompleteContext) => {
return context.interaction.respond([{ name: "heh", value: "heh" }]);
}
}
]
})

View file

@ -1,11 +1,31 @@
import { SharedNameAndDescription, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandUserOption } from "discord.js";
import { APIApplicationCommandAttachmentOption, APIApplicationCommandBasicOption, APIApplicationCommandBooleanOption, APIApplicationCommandChannelOption, APIApplicationCommandIntegerOption, APIApplicationCommandMentionableOption, APIApplicationCommandNumberOption, APIApplicationCommandOptionChoice, APIApplicationCommandRoleOption, APIApplicationCommandStringOption, APIApplicationCommandSubcommandGroupOption, APIApplicationCommandSubcommandOption, APIApplicationCommandUserOption, ApplicationCommandOptionType, LocalizationMap, SharedNameAndDescription, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandUserOption } from "discord.js";
import { AutocompleteContext } from "./context/AutocompleteContext";
import { CommandContext } from "./context/CommandContext";
export type Option = SlashCommandAttachmentOption | SlashCommandBooleanOption | SlashCommandChannelOption | SlashCommandIntegerOption | SlashCommandMentionableOption | SlashCommandNumberOption | SlashCommandRoleOption | SlashCommandUserOption | SharedNameAndDescription | StringOption;
export type Option = APIApplicationCommandAttachmentOption |
APIApplicationCommandBooleanOption |
APIApplicationCommandChannelOption |
APIApplicationCommandIntegerOption |
APIApplicationCommandMentionableOption |
APIApplicationCommandNumberOption |
APIApplicationCommandRoleOption |
APIApplicationCommandUserOption |
APIApplicationCommandSubcommandOption |
APIApplicationCommandSubcommandGroupOption |
StringOption;
interface StringOption extends SlashCommandStringOption {
run: (option: Option, interaction: AutocompleteContext) => void;
interface StringOption {
name: string;
name_localizations?: LocalizationMap;
description: string;
description_localizations?: LocalizationMap;
min_length?: number;
max_length?: number;
required?: boolean;
type: ApplicationCommandOptionType.String;
autocomplete?: boolean;
choices?: APIApplicationCommandOptionChoice[];
run: (option: Option, interaction: AutocompleteContext) => any;
}
export interface Command {

View file

@ -1,4 +1,5 @@
import { AutocompleteInteraction } from "discord.js";
import { Option } from "../Command.ts";
export class AutocompleteContext {
public option: Option;