feat: interactions (#5448)

Co-authored-by: izexi <43889168+izexi@users.noreply.github.com>
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
Co-authored-by: Advaith <advaithj1@gmail.com>
Co-authored-by: Shiaupiau <stu43005@gmail.com>
Co-authored-by: monbrey <rsm999@uowmail.edu.au>
Co-authored-by: Tiemen <ThaTiemsz@users.noreply.github.com>
Co-authored-by: Carter <carter@elhnet.net>
This commit is contained in:
Jan
2021-05-07 17:22:33 +02:00
committed by GitHub
parent af00ec8970
commit f7643f7bbe
24 changed files with 1340 additions and 35 deletions

251
typings/index.d.ts vendored
View File

@@ -21,10 +21,15 @@ declare enum ChannelTypes {
STAGE = 13,
}
declare enum StickerFormatTypes {
PNG = 1,
APNG = 2,
LOTTIE = 3,
declare enum InteractionResponseTypes {
PONG = 1,
CHANNEL_MESSAGE_WITH_SOURCE = 4,
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5,
}
declare enum InteractionTypes {
PING = 1,
APPLICATION_COMMAND = 2,
}
declare enum OverwriteTypes {
@@ -32,10 +37,25 @@ declare enum OverwriteTypes {
member = 1,
}
declare enum StickerFormatTypes {
PNG = 1,
APNG = 2,
LOTTIE = 3,
}
declare module 'discord.js' {
import BaseCollection from '@discordjs/collection';
import { ChildProcess } from 'child_process';
import { APIMessage as RawMessage, APIOverwrite as RawOverwrite } from 'discord-api-types/v8';
import {
ApplicationCommandOptionType as ApplicationCommandOptionTypes,
ApplicationCommandPermissionType as ApplicationCommandPermissionTypes,
APIInteractionDataResolvedChannel as RawInteractionDataResolvedChannel,
APIInteractionDataResolvedGuildMember as RawInteractionDataResolvedGuildMember,
APIInteractionGuildMember as RawInteractionGuildMember,
APIMessage as RawMessage,
APIOverwrite as RawOverwrite,
APIRole as RawRole,
} from 'discord-api-types/v8';
import { EventEmitter } from 'events';
import { PathLike } from 'fs';
import { Readable, Stream, Writable } from 'stream';
@@ -85,6 +105,7 @@ declare module 'discord.js' {
public readonly isUser: boolean;
public readonly isWebhook: boolean;
public readonly isMessage: boolean;
public readonly isInteraction: boolean;
public files: object[] | null;
public options: MessageOptions | WebhookMessageOptions;
public target: MessageTarget;
@@ -139,6 +160,24 @@ declare module 'discord.js' {
public toString(): string | null;
}
export class ApplicationCommand extends Base {
constructor(client: Client, data: object, guild?: Guild);
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public defaultPermission: boolean;
public description: string;
public guild: Guild | null;
public readonly manager: ApplicationCommandManager;
public id: Snowflake;
public name: string;
public options: ApplicationCommandOption[];
public delete(): Promise<ApplicationCommand>;
public edit(data: ApplicationCommandData): Promise<ApplicationCommand>;
public fetchPermissions(): Promise<ApplicationCommandPermissions[]>;
public setPermissions(permissions: ApplicationCommandPermissionData[]): Promise<ApplicationCommandPermissions[]>;
private static transformOption(option: ApplicationCommandOptionData, received?: boolean): object;
}
export class ApplicationFlags extends BitField<ApplicationFlagsString> {
public static FLAGS: Record<ApplicationFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<ApplicationFlagsString, number>): number;
@@ -300,6 +339,7 @@ declare module 'discord.js' {
export class ClientApplication extends Application {
public botPublic: boolean | null;
public botRequireCodeGrant: boolean | null;
public commands: ApplicationCommandManager;
public cover: string | null;
public flags: Readonly<ApplicationFlags>;
public owner: User | Team | null;
@@ -363,6 +403,26 @@ declare module 'discord.js' {
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => void): this;
}
export class CommandInteraction extends Interaction {
public readonly command: ApplicationCommand | null;
public commandID: string;
public commandName: string;
public deferred: boolean;
public options: CommandInteractionOption[];
public replied: boolean;
public webhook: WebhookClient;
public defer(ephemeral?: boolean): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(
content: string | APIMessage | WebhookEditMessageOptions | MessageEmbed | MessageEmbed[],
): Promise<Message | RawMessage>;
public editReply(content: string, options?: WebhookEditMessageOptions): Promise<Message | RawMessage>;
public fetchReply(): Promise<Message | RawMessage>;
public reply(content: string | APIMessage | InteractionReplyOptions | MessageAdditions): Promise<void>;
public reply(content: string, options?: InteractionReplyOptions): Promise<void>;
private transformOption(option: object, resolved: object): CommandInteractionOption;
}
type AllowedImageFormat = 'webp' | 'png' | 'jpg' | 'jpeg' | 'gif';
export const Constants: {
@@ -457,6 +517,7 @@ declare module 'discord.js' {
VOICE_BROADCAST_UNSUBSCRIBE: 'unsubscribe';
TYPING_START: 'typingStart';
WEBHOOKS_UPDATE: 'webhookUpdate';
INTERACTION_CREATE: 'interaction';
RECONNECTING: 'reconnecting';
ERROR: 'error';
WARN: 'warn';
@@ -569,6 +630,10 @@ declare module 'discord.js' {
DefaultMessageNotifications: DefaultMessageNotifications[];
VerificationLevels: VerificationLevel[];
MembershipStates: 'INVITED' | 'ACCEPTED';
ApplicationCommandOptionTypes: typeof ApplicationCommandOptionTypes;
ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes;
InteractionTypes: typeof InteractionTypes;
InteractionResponseTypes: typeof InteractionResponseTypes;
};
export class DataResolver {
@@ -629,6 +694,7 @@ declare module 'discord.js' {
public available: boolean;
public banner: string | null;
public channels: GuildChannelManager;
public commands: GuildApplicationCommandManager;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public defaultMessageNotifications: DefaultMessageNotifications | number;
@@ -967,6 +1033,24 @@ declare module 'discord.js' {
public static resolve(bit?: BitFieldResolvable<IntentsString, number>): number;
}
export class Interaction extends Base {
constructor(client: Client, data: object);
public applicationID: Snowflake;
public readonly channel: Channel | null;
public channelID: Snowflake | null;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public readonly guild: Guild | null;
public guildID: Snowflake | null;
public id: Snowflake;
public member: GuildMember | RawInteractionGuildMember | null;
public readonly token: string;
public type: InteractionType;
public user: User;
public version: number;
public isCommand(): this is CommandInteraction;
}
export class Invite extends Base {
constructor(client: Client, data: object);
public channel: GuildChannel | PartialGroupDMChannel;
@@ -1015,6 +1099,7 @@ declare module 'discord.js' {
public embeds: MessageEmbed[];
public readonly guild: Guild | null;
public id: Snowflake;
public interaction: MessageInteraction | null;
public readonly member: GuildMember | null;
public mentions: MessageMentions;
public nonce: string | number | null;
@@ -1378,7 +1463,7 @@ declare module 'discord.js' {
public eval<T>(fn: (client: Client) => T): Promise<T[]>;
public fetchClientValue(prop: string): Promise<any>;
public kill(): void;
public respawn(options?: { delay?: number, timeout?: number }): Promise<ChildProcess>;
public respawn(options?: { delay?: number; timeout?: number }): Promise<ChildProcess>;
public send(message: any): Promise<Shard>;
public spawn(timeout?: number): Promise<ChildProcess>;
@@ -1411,7 +1496,7 @@ declare module 'discord.js' {
public broadcastEval<T>(fn: (client: Client) => T, shard: number): Promise<T>;
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, shard: number): Promise<any>;
public respawnAll(options?: { shardDelay?: number, respawnDelay?: number, timeout?: number }): Promise<void>;
public respawnAll(options?: { shardDelay?: number; respawnDelay?: number; timeout?: number }): Promise<void>;
public send(message: any): Promise<void>;
public static singleton(client: Client, mode: ShardingManagerMode): ShardClientUtil;
@@ -1448,11 +1533,15 @@ declare module 'discord.js' {
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, shard: number): Promise<any>;
public respawnAll(options?: {
shardDelay?: number,
respawnDelay?: number,
timeout?: number,
shardDelay?: number;
respawnDelay?: number;
timeout?: number;
}): Promise<Collection<number, Shard>>;
public spawn(options?: {
amount?: number | 'auto';
delay?: number;
timeout?: number;
}): Promise<Collection<number, Shard>>;
public spawn(options?: { amount?: number | 'auto', delay?: number, timeout?: number }): Promise<Collection<number, Shard>>;
public on(event: 'shardCreate', listener: (shard: Shard) => void): this;
@@ -1963,6 +2052,32 @@ declare module 'discord.js' {
public valueOf(): Collection<K, Holds>;
}
export class ApplicationCommandManager extends BaseManager<
Snowflake,
ApplicationCommand,
ApplicationCommandResolvable
> {
constructor(client: Client, iterable?: Iterable<any>);
private readonly commandPath: object;
public create(command: ApplicationCommandData): Promise<ApplicationCommand>;
public delete(command: ApplicationCommandResolvable): Promise<ApplicationCommand | null>;
public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise<ApplicationCommand>;
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<ApplicationCommand>;
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, ApplicationCommand>>;
public fetchPermissions(): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>;
public fetchPermissions(command: ApplicationCommandResolvable): Promise<ApplicationCommandPermissions[]>;
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommand>>;
public setPermissions(
command: ApplicationCommandResolvable,
permissions: ApplicationCommandPermissionData[],
): Promise<ApplicationCommandPermissions[]>;
public setPermissions(
permissions: GuildApplicationCommandPermissionData[],
): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>;
private static transformCommand(command: ApplicationCommandData): object;
private static transformPermissions(permissions: ApplicationCommandPermissionData, received?: boolean): object;
}
export class BaseGuildEmojiManager extends BaseManager<Snowflake, GuildEmoji, EmojiResolvable> {
constructor(client: Client, iterable?: Iterable<any>);
public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null;
@@ -1973,6 +2088,11 @@ declare module 'discord.js' {
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Channel | null>;
}
export class GuildApplicationCommandManager extends ApplicationCommandManager {
constructor(guild: Guild, iterable?: Iterable<any>);
public guild: Guild;
}
export class GuildChannelManager extends BaseManager<Snowflake, GuildChannel, GuildChannelResolvable> {
constructor(guild: Guild, iterable?: Iterable<any>);
public guild: Guild;
@@ -2167,15 +2287,18 @@ declare module 'discord.js' {
readonly createdTimestamp: number;
readonly url: string;
delete(reason?: string): Promise<void>;
deleteMessage(message: MessageResolvable): Promise<void>;
deleteMessage(message: MessageResolvable | '@original'): Promise<void>;
edit(options: WebhookEditData): Promise<Webhook>;
editMessage(
message: MessageResolvable,
message: MessageResolvable | '@original',
content: APIMessageContentResolvable | APIMessage | MessageEmbed | MessageEmbed[],
options?: WebhookEditMessageOptions,
): Promise<Message | RawMessage>;
editMessage(message: MessageResolvable, options: WebhookEditMessageOptions): Promise<Message | RawMessage>;
fetchMessage(message: Snowflake, cache?: boolean): Promise<Message | RawMessage>;
editMessage(
message: MessageResolvable | '@original',
options: WebhookEditMessageOptions,
): Promise<Message | RawMessage>;
fetchMessage(message: Snowflake | '@original', cache?: boolean): Promise<Message | RawMessage>;
send(
content: APIMessageContentResolvable | (WebhookMessageOptions & { split?: false }) | MessageAdditions,
): Promise<Message | RawMessage>;
@@ -2299,6 +2422,47 @@ declare module 'discord.js' {
type: 'BIG' | 'SMALL';
}
interface ApplicationCommandData {
name: string;
description: string;
options?: ApplicationCommandOptionData[];
defaultPermission?: boolean;
}
interface ApplicationCommandOptionData {
type: ApplicationCommandOptionType | ApplicationCommandOptionTypes;
name: string;
description: string;
required?: boolean;
choices?: ApplicationCommandOptionChoice[];
options?: ApplicationCommandOption[];
}
interface ApplicationCommandOption extends ApplicationCommandOptionData {
type: ApplicationCommandOptionType;
}
interface ApplicationCommandOptionChoice {
name: string;
value: string | number;
}
type ApplicationCommandOptionType = keyof typeof ApplicationCommandOptionTypes;
interface ApplicationCommandPermissionData {
id: Snowflake;
type: ApplicationCommandPermissionType | ApplicationCommandPermissionTypes;
permission: boolean;
}
interface ApplicationCommandPermissions extends ApplicationCommandPermissionData {
type: ApplicationCommandPermissionType;
}
type ApplicationCommandPermissionType = keyof typeof ApplicationCommandPermissionTypes;
type ApplicationCommandResolvable = ApplicationCommand | Snowflake;
type ApplicationFlagsString =
| 'MANAGED_EMOJI'
| 'GROUP_DM_CREATE'
@@ -2428,6 +2592,7 @@ declare module 'discord.js' {
userUpdate: [oldUser: User | PartialUser, newUser: User];
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
webhookUpdate: [channel: TextChannel];
interaction: [interaction: Interaction];
shardDisconnect: [closeEvent: CloseEvent, shardID: number];
shardError: [error: Error, shardID: number];
shardReady: [shardID: number, unavailableGuilds: Set<Snowflake> | undefined];
@@ -2519,6 +2684,17 @@ declare module 'discord.js' {
| number
| string;
interface CommandInteractionOption {
name: string;
type: ApplicationCommandOptionType;
value?: string | number | boolean;
options?: CommandInteractionOption[];
user?: User;
member?: GuildMember | RawInteractionDataResolvedGuildMember;
channel?: GuildChannel | RawInteractionDataResolvedChannel;
role?: Role | RawRole;
}
interface CrosspostedChannel {
channelID: Snowflake;
guildID: Snowflake;
@@ -2590,6 +2766,7 @@ declare module 'discord.js' {
VoiceState: typeof VoiceState;
Role: typeof Role;
User: typeof User;
CommandInteraction: typeof CommandInteraction;
}
interface FetchMemberOptions {
@@ -2608,12 +2785,17 @@ declare module 'discord.js' {
force?: boolean;
}
type FetchOwnerOptions = Omit<FetchMemberOptions, 'user'>;
interface FileOptions {
attachment: BufferResolvable | Stream;
name?: string;
}
type FetchOwnerOptions = Omit<FetchMemberOptions, 'user'>;
interface GuildApplicationCommandPermissionData {
id: Snowflake;
permissions: ApplicationCommandPermissionData[];
}
type GuildAuditLogsAction = keyof GuildAuditLogsActions;
@@ -2834,6 +3016,14 @@ declare module 'discord.js' {
name: string;
}
interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> {
ephemeral?: boolean;
}
type InteractionResponseType = keyof typeof InteractionResponseTypes;
type InteractionType = keyof typeof InteractionTypes;
type IntentsString =
| 'GUILDS'
| 'GUILD_MEMBERS'
@@ -2965,7 +3155,21 @@ declare module 'discord.js' {
target: WebSocket;
}
type MessageFlagsString = 'CROSSPOSTED' | 'IS_CROSSPOST' | 'SUPPRESS_EMBEDS' | 'SOURCE_MESSAGE_DELETED' | 'URGENT';
type MessageFlagsString =
| 'CROSSPOSTED'
| 'IS_CROSSPOST'
| 'SUPPRESS_EMBEDS'
| 'SOURCE_MESSAGE_DELETED'
| 'URGENT'
| 'EPHEMERAL'
| 'LOADING';
interface MessageInteraction {
id: Snowflake;
type: InteractionType;
commandName: string;
user: User;
}
interface MessageMentionOptions {
parse?: MessageMentionTypes[];
@@ -3018,7 +3222,8 @@ declare module 'discord.js' {
| 'GUILD_DISCOVERY_REQUALIFIED'
| 'GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING'
| 'GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING'
| 'REPLY';
| 'REPLY'
| 'APPLICATION_COMMAND';
interface OverwriteData {
allow?: PermissionResolvable;
@@ -3071,6 +3276,7 @@ declare module 'discord.js' {
| 'MANAGE_ROLES'
| 'MANAGE_WEBHOOKS'
| 'MANAGE_EMOJIS'
| 'USE_APPLICATION_COMMANDS'
| 'REQUEST_TO_SPEAK';
interface RecursiveArray<T> extends ReadonlyArray<T | RecursiveArray<T>> {}
@@ -3309,7 +3515,7 @@ declare module 'discord.js' {
type SystemChannelFlagsResolvable = BitFieldResolvable<SystemChannelFlagsString, number>;
type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY'>;
type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY' | 'APPLICATION_COMMAND'>;
type TargetUser = number;
@@ -3360,11 +3566,11 @@ declare module 'discord.js' {
type WebhookEditMessageOptions = Pick<WebhookMessageOptions, 'content' | 'embeds' | 'files' | 'allowedMentions'>;
type WebhookMessageOptions = Omit<MessageOptions, 'embed' | 'replyTo'> & {
interface WebhookMessageOptions extends Omit<MessageOptions, 'embed' | 'replyTo'> {
username?: string;
avatarURL?: string;
embeds?: (MessageEmbed | object)[];
};
}
type WebhookTypes = 'Incoming' | 'Channel Follower';
@@ -3416,7 +3622,8 @@ declare module 'discord.js' {
| 'TYPING_START'
| 'VOICE_STATE_UPDATE'
| 'VOICE_SERVER_UPDATE'
| 'WEBHOOKS_UPDATE';
| 'WEBHOOKS_UPDATE'
| 'INTERACTION_CREATE';
//#endregion
}