From 665bf1486aec62e9528f5f7b5a6910ae6b5a6c9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?T=C3=86MB=C3=98?= <69138346+TAEMBO@users.noreply.github.com>
Date: Tue, 17 Sep 2024 01:18:08 -0700
Subject: [PATCH] types(MessageEditOptions): Omit `poll` (#10509)
fix: creating poll from message edit
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
---
packages/discord.js/src/structures/Webhook.js | 2 +-
.../structures/interfaces/InteractionResponses.js | 2 +-
.../src/structures/interfaces/TextBasedChannel.js | 7 ++++++-
packages/discord.js/typings/index.d.ts | 13 +++++++++----
packages/discord.js/typings/index.test-d.ts | 10 ++++++++++
5 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js
index 9b2bad0d5467..e52ec14040ae 100644
--- a/packages/discord.js/src/structures/Webhook.js
+++ b/packages/discord.js/src/structures/Webhook.js
@@ -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.
* Only the {@link MessageFlags.SuppressEmbeds} flag can be set.
diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js
index 9f711b517b49..440242a34e56 100644
--- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js
+++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js
@@ -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
diff --git a/packages/discord.js/src/structures/interfaces/TextBasedChannel.js b/packages/discord.js/src/structures/interfaces/TextBasedChannel.js
index c3f5a9e6c573..d2e408580253 100644
--- a/packages/discord.js/src/structures/interfaces/TextBasedChannel.js
+++ b/packages/discord.js/src/structures/interfaces/TextBasedChannel.js
@@ -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
*/
@@ -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
* This property is required if `enforceNonce` set to `true`.
diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts
index 2ac27e78a990..771623c5cff5 100644
--- a/packages/discord.js/typings/index.d.ts
+++ b/packages/discord.js/typings/index.d.ts
@@ -6291,7 +6291,7 @@ export interface InteractionDeferReplyOptions {
export interface InteractionDeferUpdateOptions extends Omit {}
-export interface InteractionReplyOptions extends BaseMessageOptions {
+export interface InteractionReplyOptions extends BaseMessageOptionsWithPoll {
tts?: boolean;
ephemeral?: boolean;
fetchReply?: boolean;
@@ -6459,10 +6459,13 @@ export interface BaseMessageOptions {
| ActionRowData
| APIActionRowComponent
)[];
+}
+
+export interface BaseMessageOptionsWithPoll extends BaseMessageOptions {
poll?: PollData;
}
-export interface MessageCreateOptions extends BaseMessageOptions {
+export interface MessageCreateOptions extends BaseMessageOptionsWithPoll {
tts?: boolean;
nonce?: string | number;
enforceNonce?: boolean;
@@ -6475,7 +6478,7 @@ export interface MessageCreateOptions extends BaseMessageOptions {
}
export interface GuildForumThreadMessageCreateOptions
- extends Omit,
+ extends BaseMessageOptions,
Pick {}
export interface MessageEditAttachmentData {
@@ -6981,7 +6984,9 @@ export interface WebhookMessageEditOptions extends Omit {
message?: MessageResolvable | '@original';
}
diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts
index 1f499be832d6..f23023f1acca 100644
--- a/packages/discord.js/typings/index.test-d.ts
+++ b/packages/discord.js/typings/index.test-d.ts
@@ -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';
@@ -2576,6 +2577,8 @@ await textChannel.send({
});
declare const poll: Poll;
+declare const message: Message;
+declare const pollData: PollData;
{
expectType(await poll.end());
@@ -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>(await client.fetchStickerPacks());