Hi, I'm trying to find the correct type/interface for the Interaction object which is sent by Discord to my endpoint using the types found in the DiscordJS library.
I'm not sure if this is the correct one but I'm trying with APIInteraction from discord.js and can kind of scope the interface to give somewhat correct typing depending if it's an application command or message component like this:
import { APIInteraction, InteractionType } from 'discord.js';
export interface Interaction {
run: (interaction: APIInteraction) => Promise<void>;
}
const testCommand: Interaction = {
run: async (interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) {
interaction.data.name;
} else if (interaction.type === InteractionType.MessageComponent) {
interaction.data.custom_id;
}
},
};
With this, the "somewhat" correct typing for interaction.data. show up depending on the if scope.
The issue I'm having right now is getting the application command if statement recognising that the interaction object may be one with an options field, used for subcommand interactions.
Is there anything I can do to scope the APIInteraction type to recognise the options field in application commands or do I need to readdress this approach with other typings (if so which typings)?
Thanks!