Skip to content

Commit

Permalink
docs improvements
Browse files Browse the repository at this point in the history
Constants.InteractionResponseType => Constants.InteractionResponseTypes
Moved ts docs to the same spot
Added more missing ts docs
Fixed some js docs

Added "Errors with ephemeral messages." to editParent

Fix some docs

Fix and improve ts docs
Fix createInteractionResponse docs
  • Loading branch information
JustCat80 committed Jul 24, 2021
1 parent a2d340a commit d3bca79
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 46 deletions.
70 changes: 45 additions & 25 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@ declare namespace Eris {

// TYPES

type InteractionOptions = {
allowedMentions?: AllowedMentions;
content?: string;
embeds?: EmbedOptions;
flags?: number;
tts?: boolean;
type: number;
};

type InteractionContent = Pick<InteractionOptions, "content" | "embeds" | "flags" | "allowedMentions" | "tts">;

interface InteractionWebhookContent {
allowedMentions?: AllowedMentions;
content?: string;
embeds?: EmbedOptions[];
file?: MessageFile | MessageFile[];
flags?: number;
tts?: boolean;
}

// Cache
type Uncached = { id: string };

Expand Down Expand Up @@ -89,7 +69,33 @@ declare namespace Eris {
type MessageContent = string | AdvancedMessageContent;
type MFALevel = 0 | 1;
type PossiblyUncachedMessage = Message | { channel: TextableChannel | { id: string; guild?: Uncached }; guildID?: string; id: string };

// Interaction
type InteractionType = 1 | 2 | 3;
type InteractionResponseType = 1 | 4 | 5 | 6 | 7;
type SlashCommandOptionType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

type InteractionDataOptions = {
name: string;
type: SlashCommandOptionType;
value?: SlashCommandOptionType;
options?: [InteractionDataOptions];
};

type InteractionOptions = {
type: InteractionResponseType;
data?: InteractionContent;
};

type InteractionContent = {
allowedMentions?: AllowedMentions;
content?: string;
embeds?: EmbedOptions;
flags?: number;
tts?: boolean;
};

type InteractionWebhookContent = Pick<WebhookPayload, "content" | "embeds" | "file" | "allowedMentions" | "tts" | "flags">;

// Permission
type PermissionType = 0 | 1;
Expand Down Expand Up @@ -1346,6 +1352,18 @@ declare namespace Eris {
RESUMED: 9;
DISCONNECT: 13;
};
InteractionTypes: {
ping: 1;
slashCommand: 2;
messageComponent: 3;
};
InteractionResponseTypes: {
PONG: 1;
CHANNEL_MESSAGE_WITH_SOURCE: 4;
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE: 5;
DEFERRED_UPDATE_MESSAGE: 6;
UPDATE_MESSAGE: 7;
};
}

// Selfbot
Expand Down Expand Up @@ -2237,18 +2255,20 @@ declare namespace Eris {
applicationId: string;
channelId: string;
data?: {
componentType?: number;
componentType?: 2 | 3;
id?: string;
custom_id?: string;
name?: string;
options?: { name?: string; value: string }
options?: [InteractionDataOptions];
values?: [string];
};
guildId?: string;
id: string;
member: Member;
message: Message;
member?: Member;
message?: Message;
token: string;
type: number;
type: InteractionType;
user?: User;
version: number;
acknowledge(): Promise<void>;
createFollowup(content: string | InteractionWebhookContent): Promise<Message<GuildTextableChannel>>;
Expand Down
20 changes: 11 additions & 9 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,18 +570,20 @@ class Client extends EventEmitter {
}

/**
* Respond to the interaction with a message !use createFollowup if you have already responded with a different method
* Respond to the interaction with a message
* Note: Use webhooks if you have already responded with an interaction response.
* @arg {String} interactionID The interaction ID.
* @arg {String} interactionToken The interaction Token.
* @arg {Object} options The options object.
* @arg {Object} [options.allowedMentions] A list of mentions to allow (overrides default)
* @arg {Boolean} [options.allowedMentions.everyone] Whether or not to allow @everyone/@here.
* @arg {Boolean | Array<String>} [options.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
* @arg {Boolean | Array<String>} [options.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {String} [options.content] A content string
* @arg {Object} [options.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Boolean} [options.flags] 64 for Ephemeral (Applies to Slash Commands and Message Components)
* @arg {Boolean} [options.tts] Set the message TTS flag
* @arg {Object} [options.data] The data to send with the response.
* @arg {Object} [options.data.allowedMentions] A list of mentions to allow (overrides default)
* @arg {Boolean} [options.data.allowedMentions.everyone] Whether or not to allow @everyone/@here.
* @arg {Boolean | Array<String>} [options.data.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
* @arg {Boolean | Array<String>} [options.data.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {String} [options.data.content] A content string
* @arg {Object} [options.data.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Boolean} [options.data.flags] 64 for Ephemeral (Applies to Slash Commands and Message Components)
* @arg {Boolean} [options.data.tts] Set the message TTS flag
* @arg {Number} options.type The response type to send [Check Discord docs for valid responses](https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactioncallbacktype).
* @returns {Promise}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ module.exports.InteractionTypes = {
messageComponent: 3
};

module.exports.InteractionResponseType = {
module.exports.InteractionResponseTypes = {
PONG: 1,
CHANNEL_MESSAGE_WITH_SOURCE: 4,
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE: 5,
Expand Down
24 changes: 13 additions & 11 deletions lib/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ const Constants = require("../Constants");
* @prop {String?} data.id The ID of the Slash Command (Slash Command)
* @prop {String?} data.name The command name (Slash Command only)
* @prop {Array<Object>?} data.options The run Slash Command options (Slash Command only)
* @prop {String?} data.options.name The name of the Slash Command option (Slash Command only)
* @prop {String?} data.options.value The value of the run Slash Command (Slash Command only)
* @prop {String} data.options.name The name of the Slash Command option
* @prop {Number} data.options.type Command option type, 1-9
* @prop {Number?} data.options.value The value of the run Slash Command (Mutually exclusive with options)
* @prop {Array<Object>?} data.options.options The run Slash Command options (Mutually exclusive with value)
* @prop {String?} guildId The id of the guild in which the interaction was created
* @prop {String} id The interaction id
* @prop {Member?} member the member who triggered the interaction
* @prop {Member?} member the member who triggered the interaction (This is only sene when the interaction is invoked within a guild)
* @prop {Message?} message The message the interaction came from (Message Component only)
* @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.)
* @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.)
* @prop {Number} type 1 is a Ping, 2 is a Slash Command, 3 is a Message Component
* @prop {User?} user the user who triggered the interaction (This is only send when the interaction is invoked within a dm)
* @prop {User?} user the user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
* @prop {Number} version The interaction version
*/
class Interaction extends Base {
Expand Down Expand Up @@ -74,7 +76,7 @@ class Interaction extends Base {
*/
async acknowledge() {
return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
type: Constants.InteractionResponseType.DEFERRED_UPDATE_MESSAGE
type: Constants.InteractionResponseTypes.DEFERRED_UPDATE_MESSAGE
});
}

Expand Down Expand Up @@ -137,7 +139,7 @@ class Interaction extends Base {
}
}
return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
type: Constants.InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
type: Constants.InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE,
data: content
});
}
Expand All @@ -150,7 +152,7 @@ class Interaction extends Base {
*/
async defer(flags) {
return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
type: Constants.InteractionResponseType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
type: Constants.InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
data: {
flags: flags || 0
}
Expand All @@ -164,7 +166,7 @@ class Interaction extends Base {
*/
async deferUpdate() {
return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
type: Constants.InteractionResponseType.DEFERRED_UPDATE_MESSAGE
type: Constants.InteractionResponseTypes.DEFERRED_UPDATE_MESSAGE
});
}

Expand Down Expand Up @@ -208,7 +210,7 @@ class Interaction extends Base {

/**
* Edit the interaction Message (Message Component only)
* Note: You can **not** use more than 1 initial interaction response per interaction, use edit if you have already responded with a different interaction response.
* Note: You can **not** use more than 1 initial interaction response per interaction, use edit if you have already responded with a different interaction response. Errors with ephemeral messages.
* @arg {String | Object} content What to edit the message with
* @arg {Object} [content.allowedMentions] A list of mentions to allow (overrides default)
* @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here.
Expand Down Expand Up @@ -238,7 +240,7 @@ class Interaction extends Base {
}
}
return this._client.createInteractionResponse.call(this._client, this.id, this.token, {
type: Constants.InteractionResponseType.UPDATE_MESSAGE,
type: Constants.InteractionResponseTypes.UPDATE_MESSAGE,
data: content
});
}
Expand Down

0 comments on commit d3bca79

Please sign in to comment.