mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
Fixed interaction payload/data type
This commit is contained in:
+1
-1
@@ -14,5 +14,5 @@ export { Message, type MessagePayload, ComponentStyle, ComponentType } from './t
|
|||||||
export { Embed } from './types/embed';
|
export { Embed } from './types/embed';
|
||||||
export { Emoji } from './types/emoji';
|
export { Emoji } from './types/emoji';
|
||||||
// Other
|
// Other
|
||||||
export { createCommandHandler } from './types/handler';
|
export { createCommandHandler, type InteractionData, type InteractionCommpoentData, type InteractionCommandData, type InteractionHandlerFunction } from './types/handler';
|
||||||
export { ApplicationCommandType, ApplicationCommandOptionType as CommandOptionType } from './types/applicationCommand';
|
export { ApplicationCommandType, ApplicationCommandOptionType as CommandOptionType } from './types/applicationCommand';
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { exists } from "../utils";
|
||||||
import { ApplicationCommandContext, ApplicationCommandOptionType, type ApplicationCommandOption } from "./applicationCommand";
|
import { ApplicationCommandContext, ApplicationCommandOptionType, type ApplicationCommandOption } from "./applicationCommand";
|
||||||
import { Trait, type EventPayload } from "./common";
|
import { Trait, type EventPayload } from "./common";
|
||||||
import type { Context } from "./context";
|
import type { Context } from "./context";
|
||||||
@@ -160,10 +161,11 @@ export function createCommandHandler<T extends readonly ApplicationCommandOption
|
|||||||
return new CommandHandler(handler);
|
return new CommandHandler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandHandlerFunction = (context: Context, args: any[]) => Promise<void> | void;
|
export type CommandHandlerFunction = (context: Context, args: any[]) => Promise<any> | any;
|
||||||
export type EventHandlerFunction = (context: Context | null, payload: EventPayload) => Promise<void> | void;
|
export type EventHandlerFunction = (context: Context | null, payload: EventPayload) => Promise<any> | any;
|
||||||
|
export type InteractionHandlerFunction<P = InteractionData> = (context: Context, payload: P) => Promise<any> | any;
|
||||||
|
|
||||||
export type HandlerWithoutContext = EventHandlerFunction;
|
export type HandlerWithoutContext = EventHandlerFunction;
|
||||||
export type HanderWithContext = CommandHandlerFunction | CommandHandler<readonly ApplicationCommandOption[]>;
|
export type HanderWithContext = InteractionHandlerFunction | CommandHandlerFunction | CommandHandler<readonly ApplicationCommandOption[]>;
|
||||||
|
|
||||||
export type Handler = EventHandlerFunction | CommandHandlerFunction | CommandHandler<readonly ApplicationCommandOption[]>;
|
export type Handler = InteractionHandlerFunction<InteractionCommpoentData> | InteractionHandlerFunction<InteractionCommandData> | EventHandlerFunction | CommandHandlerFunction | CommandHandler<readonly ApplicationCommandOption[]>;
|
||||||
+11
-8
@@ -1,5 +1,4 @@
|
|||||||
import { Client, ComponentStyle, type Context, createCommandHandler, Expectation, Intent, InteractionPayload, Message, type MessagePayload } from '../src/index';
|
import { ApplicationCommandType, Client, CommandOptionType, ComponentStyle, type Context, createCommandHandler, Expectation, Intent, InteractionCommpoentData, type InteractionData, Message, type MessagePayload } from '../src/index';
|
||||||
import { ApplicationCommandOptionType, ApplicationCommandType } from '../src/types/applicationCommand';
|
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
token: process.env.BOT_TOKEN!,
|
token: process.env.BOT_TOKEN!,
|
||||||
@@ -33,21 +32,21 @@ client.applicationCommands.register('hello', ApplicationCommandType.Chat, create
|
|||||||
description: "Introduce yourself",
|
description: "Introduce yourself",
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
type: ApplicationCommandOptionType.String,
|
type: CommandOptionType.String,
|
||||||
name: "name",
|
name: "name",
|
||||||
id: "name",
|
id: "name",
|
||||||
description: "Your name",
|
description: "Your name",
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ApplicationCommandOptionType.Integer,
|
type: CommandOptionType.Integer,
|
||||||
name: "age",
|
name: "age",
|
||||||
id: "age",
|
id: "age",
|
||||||
description: "Your age",
|
description: "Your age",
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ApplicationCommandOptionType.String,
|
type: CommandOptionType.String,
|
||||||
name: "favorite_animal",
|
name: "favorite_animal",
|
||||||
id: "favorite_animal",
|
id: "favorite_animal",
|
||||||
description: "Your favorite animal",
|
description: "Your favorite animal",
|
||||||
@@ -186,7 +185,7 @@ client.chatCommands.register('demo', async (context: Context, _args: any[]) => {
|
|||||||
context.reply(msg);
|
context.reply(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
const buttonInteractionHandler = (context: Context, data: InteractionData) => {
|
const buttonInteractionHandler = (context: Context, data: InteractionCommpoentData) => {
|
||||||
context.reply(`You clicked the ${data.custom_id} button!`);
|
context.reply(`You clicked the ${data.custom_id} button!`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -197,8 +196,12 @@ client.interactions.register('button_4', buttonInteractionHandler);
|
|||||||
client.interactions.register('button_5', buttonInteractionHandler);
|
client.interactions.register('button_5', buttonInteractionHandler);
|
||||||
client.interactions.register('button_6', buttonInteractionHandler);
|
client.interactions.register('button_6', buttonInteractionHandler);
|
||||||
|
|
||||||
client.interactions.register('select_1', async (context: Context, data: InteractionData) => {
|
client.interactions.register('select_1', async (context: Context, data: InteractionCommpoentData) => {
|
||||||
context.reply(`You selected ${data.values[0]}!`);
|
if (data?.values !== undefined) {
|
||||||
|
context.reply(`You selected ${data.values[0]}!`);
|
||||||
|
} else {
|
||||||
|
context.reply('You selected nothing!');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.connect();
|
client.connect();
|
||||||
Reference in New Issue
Block a user