Skip to content

Commit

Permalink
types(MessageEditOptions): Omit poll (#10509)
Browse files Browse the repository at this point in the history
fix: creating poll from message edit

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
TAEMBO and Jiralite authored Sep 17, 2024
1 parent 99136d6 commit 665bf14
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Webhook {

/**
* Options that can be passed into send.
* @typedef {BaseMessageOptions} WebhookMessageCreateOptions
* @typedef {BaseMessageOptionsWithPoll} WebhookMessageCreateOptions
* @property {boolean} [tts=false] Whether the message should be spoken aloud
* @property {MessageFlags} [flags] Which flags to set for the message.
* <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be set.</info>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InteractionResponses {

/**
* Options for a reply to a {@link BaseInteraction}.
* @typedef {BaseMessageOptions} InteractionReplyOptions
* @typedef {BaseMessageOptionsWithPoll} InteractionReplyOptions
* @property {boolean} [tts=false] Whether the message should be spoken aloud
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
* @property {boolean} [fetchReply] Whether to fetch the reply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class TextBasedChannel {
* The files to send with the message.
* @property {Array<(ActionRowBuilder|ActionRow|APIActionRowComponent)>} [components]
* Action rows containing interactive components for the message (buttons, select menus)
*/

/**
* The base message options for messages including a poll.
* @typedef {BaseMessageOptions} BaseMessageOptionsWithPoll
* @property {PollData} [poll] The poll to send with the message
*/

Expand All @@ -93,7 +98,7 @@ class TextBasedChannel {

/**
* The options for sending a message.
* @typedef {BaseMessageOptions} BaseMessageCreateOptions
* @typedef {BaseMessageOptionsWithPoll} BaseMessageCreateOptions
* @property {boolean} [tts=false] Whether the message should be spoken aloud
* @property {string} [nonce] The nonce for the message
* <info>This property is required if `enforceNonce` set to `true`.</info>
Expand Down
13 changes: 9 additions & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6291,7 +6291,7 @@ export interface InteractionDeferReplyOptions {

export interface InteractionDeferUpdateOptions extends Omit<InteractionDeferReplyOptions, 'ephemeral'> {}

export interface InteractionReplyOptions extends BaseMessageOptions {
export interface InteractionReplyOptions extends BaseMessageOptionsWithPoll {
tts?: boolean;
ephemeral?: boolean;
fetchReply?: boolean;
Expand Down Expand Up @@ -6459,10 +6459,13 @@ export interface BaseMessageOptions {
| ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>
| APIActionRowComponent<APIMessageActionRowComponent>
)[];
}

export interface BaseMessageOptionsWithPoll extends BaseMessageOptions {
poll?: PollData;
}

export interface MessageCreateOptions extends BaseMessageOptions {
export interface MessageCreateOptions extends BaseMessageOptionsWithPoll {
tts?: boolean;
nonce?: string | number;
enforceNonce?: boolean;
Expand All @@ -6475,7 +6478,7 @@ export interface MessageCreateOptions extends BaseMessageOptions {
}

export interface GuildForumThreadMessageCreateOptions
extends Omit<BaseMessageOptions, 'poll'>,
extends BaseMessageOptions,
Pick<MessageCreateOptions, 'flags' | 'stickers'> {}

export interface MessageEditAttachmentData {
Expand Down Expand Up @@ -6981,7 +6984,9 @@ export interface WebhookMessageEditOptions extends Omit<MessageEditOptions, 'fla
threadId?: Snowflake;
}

export interface InteractionEditReplyOptions extends WebhookMessageEditOptions {
export interface InteractionEditReplyOptions
extends WebhookMessageEditOptions,
Pick<BaseMessageOptionsWithPoll, 'poll'> {
message?: MessageResolvable | '@original';
}

Expand Down
10 changes: 10 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ import {
ApplicationEmojiManager,
StickerPack,
SendableChannels,
PollData,
} from '.';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -2576,6 +2577,8 @@ await textChannel.send({
});

declare const poll: Poll;
declare const message: Message;
declare const pollData: PollData;
{
expectType<Message>(await poll.end());

Expand All @@ -2589,6 +2592,13 @@ declare const poll: Poll;
messageId: snowflake,
answerId: 1,
});

await message.edit({
// @ts-expect-error
poll: pollData,
});

await chatInputInteraction.editReply({ poll: pollData });
}

expectType<Collection<Snowflake, StickerPack>>(await client.fetchStickerPacks());
Expand Down

0 comments on commit 665bf14

Please sign in to comment.