From 0474a4375146b57b35074dadbaa83274416f899e Mon Sep 17 00:00:00 2001 From: DD Date: Sat, 4 May 2024 22:06:03 +0300 Subject: [PATCH] fix(MessageManager): poll methods don't need a channel id (#10249) * fix(MessageManager): end poll does not need channel id * chore: rest of the work --- packages/discord.js/src/managers/MessageManager.js | 10 ++++------ packages/discord.js/src/structures/Poll.js | 2 +- packages/discord.js/src/structures/PollAnswer.js | 1 - packages/discord.js/typings/index.d.ts | 3 +-- packages/discord.js/typings/index.test-d.ts | 3 +-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/discord.js/src/managers/MessageManager.js b/packages/discord.js/src/managers/MessageManager.js index b88cbc99f..dcddf2857 100644 --- a/packages/discord.js/src/managers/MessageManager.js +++ b/packages/discord.js/src/managers/MessageManager.js @@ -269,19 +269,17 @@ class MessageManager extends CachedManager { /** * Ends a poll. - * @param {Snowflake} channelId The id of the channel * @param {Snowflake} messageId The id of the message * @returns {Promise} */ - async endPoll(channelId, messageId) { - const message = await this.client.rest.post(Routes.expirePoll(channelId, messageId)); + async endPoll(messageId) { + const message = await this.client.rest.post(Routes.expirePoll(this.channel.id, messageId)); return this._add(message, false); } /** * Options used for fetching voters of an answer in a poll. * @typedef {BaseFetchPollAnswerVotersOptions} FetchPollAnswerVotersOptions - * @param {Snowflake} channelId The id of the channel * @param {Snowflake} messageId The id of the message * @param {number} answerId The id of the answer */ @@ -291,8 +289,8 @@ class MessageManager extends CachedManager { * @param {FetchPollAnswerVotersOptions} options The options for fetching the poll answer voters * @returns {Promise>} */ - async fetchPollAnswerVoters({ channelId, messageId, answerId, after, limit }) { - const voters = await this.client.rest.get(Routes.pollAnswerVoters(channelId, messageId, answerId), { + async fetchPollAnswerVoters({ messageId, answerId, after, limit }) { + const voters = await this.client.rest.get(Routes.pollAnswerVoters(this.channel.id, messageId, answerId), { query: makeURLSearchParams({ limit, after }), }); diff --git a/packages/discord.js/src/structures/Poll.js b/packages/discord.js/src/structures/Poll.js index 710ac267c..90c1f5af0 100644 --- a/packages/discord.js/src/structures/Poll.js +++ b/packages/discord.js/src/structures/Poll.js @@ -102,7 +102,7 @@ class Poll extends Base { return Promise.reject(new DiscordjsError(ErrorCodes.PollAlreadyExpired)); } - return this.message.channel.messages.endPoll(this.message.channel.id, this.message.id); + return this.message.channel.messages.endPoll(this.message.id); } } diff --git a/packages/discord.js/src/structures/PollAnswer.js b/packages/discord.js/src/structures/PollAnswer.js index 68ce7e56c..1cdcc7c75 100644 --- a/packages/discord.js/src/structures/PollAnswer.js +++ b/packages/discord.js/src/structures/PollAnswer.js @@ -78,7 +78,6 @@ class PollAnswer extends Base { */ fetchVoters({ after, limit } = {}) { return this.poll.message.channel.fetchPollAnswerVoters({ - channelId: this.poll.message.channel.id, messageId: this.poll.message.id, answerId: this.id, after, diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 2cf49f108..76fdcc12c 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4399,7 +4399,6 @@ export class GuildMemberRoleManager extends DataManager extends public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise; public pin(message: MessageResolvable, reason?: string): Promise; public unpin(message: MessageResolvable, reason?: string): Promise; - public endPoll(channelId: Snowflake, messageId: Snowflake): Promise; + public endPoll(messageId: Snowflake): Promise; public fetchPollAnswerVoters(options: FetchPollAnswerVotersOptions): Promise>; } diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 6b867b39a..d9b212f23 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -2549,9 +2549,8 @@ declare const poll: Poll; expectType>(await answer.fetchVoters({ after: snowflake, limit: 10 })); - await messageManager.endPoll(snowflake, snowflake); + await messageManager.endPoll(snowflake); await messageManager.fetchPollAnswerVoters({ - channelId: snowflake, messageId: snowflake, answerId: 1, });