slash-create-modify
Version:
Create and sync Discord slash commands!
188 lines (187 loc) • 8.96 kB
TypeScript
/// <reference types="node" />
import { ComponentActionRow } from '../../constants';
import { SlashCreator, ComponentRegisterCallback } from '../../creator';
import { RespondFunction } from '../../server';
import { MessageAllowedMentions } from '../../util';
import { Member } from '../member';
import { User } from '../user';
import { Message, MessageEmbedOptions } from '../message';
import { Permissions } from '../permissions';
/** Represents a interaction context that handles messages. */
export declare class MessageInteractionContext {
/** The creator of the interaction request. */
readonly creator: SlashCreator;
/** The interaction's token. */
readonly interactionToken: string;
/** The interaction's ID. */
readonly interactionID: string;
/** The channel ID that the interaction was invoked in. */
readonly channelID: string;
/** The guild ID that the interaction was invoked in. */
readonly guildID?: string;
/** The user's locale */
readonly locale?: string;
/** The guild's perferred locale, if invoked in a guild. */
readonly guildLocale?: string;
/** The member that invoked the interaction. */
readonly member?: Member;
/** The user that invoked the interaction. */
readonly user: User;
/** The time when the interaction was created. */
readonly invokedAt: number;
/** The permissions the application has. */
readonly appPermissions?: Permissions;
/** Whether the initial response was sent. */
initiallyResponded: boolean;
/** Whether there is a deferred message available. */
deferred: boolean;
/** The original message ID, automatically set when editing/fetching original message. */
messageID?: string;
channel?: any;
message?: any;
/** @hidden */
protected _respond: RespondFunction;
/** @hidden */
protected _timeout?: any;
/**
* @param creator The instantiating creator.
* @param data The interaction data.
* @param respond The response function for the interaction.
*/
constructor(creator: SlashCreator, data: any, respond: RespondFunction);
/** Whether the interaction has expired. Interactions last 15 minutes. */
get expired(): boolean;
/**
* Fetches a message.
* @param messageID The ID of the message, defaults to the original message
*/
fetch(messageID?: string): Promise<Message>;
/**
* Sends a message, if it already made an initial response, this will create a follow-up message.
* IF the context has created a deferred message, it will edit that deferred message,
* and future calls to this function create follow ups.
* This will return a boolean if it's an initial response, otherwise a {@link Message} will be returned.
* Note that when making a follow-up message, the `ephemeral` option is ignored.
* @param content The content of the message
* @param options The message options
*/
send(content: string | MessageOptions, options?: MessageOptions): Promise<boolean | Message>;
/**
* Sends a follow-up message.
* @param content The content of the message
* @param options The message options
*/
sendFollowUp(content: string | MessageOptions, options?: MessageOptions): Promise<Message>;
/**
* Edits a message.
* @param messageID The message's ID
* @param content The content of the message
* @param options The message options
*/
edit(messageID: string, content: string | EditMessageOptions, options?: EditMessageOptions): Promise<Message>;
/**
* Edits the original message.
* Note: This will error with ephemeral messages or deferred ephemeral messages.
* @param content The content of the message
* @param options The message options
*/
editOriginal(content: string | EditMessageOptions, options?: EditMessageOptions): Promise<Message>;
/**
* Deletes a message. If the message ID was not defined, the original message is used.
* @param messageID The message's ID
*/
delete(messageID?: string): Promise<any>;
/**
* Creates a deferred message. To users, this will show as
* "Bot is thinking..." until the deferred message is edited.
* @param ephemeral Whether to make the deferred message ephemeral.
* @returns Whether the deferred message passed
*/
defer(ephemeral?: boolean): Promise<boolean>;
/**
* Registers a component callback from the initial message.
* This unregisters automatically when the context expires.
* @param custom_id The custom ID of the component to register
* @param callback The callback to use on interaction
* @param expiration The expiration time of the callback in milliseconds. Use null for no expiration (Although, in this case, global components might be more consistent).
* @param onExpired A function to be called when the component expires.
*/
registerComponent(custom_id: string, callback: ComponentRegisterCallback, expiration?: number, onExpired?: () => void): void;
/**
* Registers a component callback from a message.
* This unregisters automatically when the context expires.
* @param message_id The message ID of the component to register
* @param custom_id The custom ID of the component to register
* @param callback The callback to use on interaction
* @param expiration The expiration time of the callback in milliseconds. Use null for no expiration (Although, in this case, global components might be more consistent).
* @param onExpired A function to be called when the component expires.
*/
registerComponentFrom(message_id: string, custom_id: string, callback: ComponentRegisterCallback, expiration?: number, onExpired?: () => void): void;
/**
* Unregisters a component callback.
* @param custom_id The custom ID of the component to unregister
* @param message_id The message ID of the component to unregister, defaults to initial message ID if any
*/
unregisterComponent(custom_id: string, message_id?: string): boolean;
/**
* Registers a wildcard component callback on a message.
* This unregisters automatically when the context expires.
* @param message_id The message ID of the component to register
* @param callback The callback to use on interaction
* @param expiration The expiration time of the callback in milliseconds. Use null for no expiration (Although, in this case, global components might be more consistent).
* @param onExpired A function to be called when the component expires.
*/
registerWildcardComponent(message_id: string, callback: ComponentRegisterCallback, expiration?: number, onExpired?: () => void): void;
/**
* Unregisters a component callback.
* @param message_id The message ID of the component to unregister, defaults to the invoking message ID.
*/
unregisterWildcardComponent(message_id: string): boolean;
}
/** The options for {@link MessageInteractionContext#edit}. */
export interface EditMessageOptions {
/** The message content. */
content?: string;
/** The embeds of the message. */
embeds?: MessageEmbedOptions[];
/** The mentions allowed to be used in this message. */
allowedMentions?: MessageAllowedMentions;
/**
* The attachment(s) to send with the message.
* Note that ephemeral messages and initial messages cannot have
* attachments.
*/
file?: MessageFile | MessageFile[];
/** The components of the message. */
components?: ComponentActionRow[];
/** The attachment data of the message. */
attachments?: MessageAttachmentOptions[];
}
/** A file within {@link EditMessageOptions}. */
export interface MessageFile {
/** The attachment to send. */
file: Buffer;
/** The name of the file. */
name: string;
}
/** A message attachment describing a file. */
export interface MessageAttachmentOptions {
/** The name of the attachment. */
name?: string;
/** The ID of the attachment. For existing attachments, this must be the ID snowflake of the attachment, otherwise, this will be the index of the files being sent to Discord. */
id: string | number;
/** The description of the attachment. */
description?: string;
}
/** The options for {@link MessageInteractionContext#send} and {@link MessageInteractionContext#sendFollowUp}. */
export interface MessageOptions extends EditMessageOptions {
/** Whether to use TTS for the content. */
tts?: boolean;
/** The flags to use in the message. */
flags?: number;
/**
* Whether or not the message should be ephemeral.
* Ignored if `flags` is defined.
*/
ephemeral?: boolean;
}