Skip to content

Commit

Permalink
fix(MessageManager): poll methods don't need a channel id (#10249)
Browse files Browse the repository at this point in the history
* fix(MessageManager): end poll does not need channel id

* chore: rest of the work
  • Loading branch information
didinele authored May 4, 2024
1 parent c91d03c commit 0474a43
Showing 5 changed files with 7 additions and 12 deletions.
10 changes: 4 additions & 6 deletions packages/discord.js/src/managers/MessageManager.js
Original file line number Diff line number Diff line change
@@ -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<Message>}
*/
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<Collection<Snowflake, User>>}
*/
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 }),
});

2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Poll.js
Original file line number Diff line number Diff line change
@@ -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);
}
}

1 change: 0 additions & 1 deletion packages/discord.js/src/structures/PollAnswer.js
Original file line number Diff line number Diff line change
@@ -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,
3 changes: 1 addition & 2 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -4399,7 +4399,6 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
}

export interface FetchPollAnswerVotersOptions extends BaseFetchPollAnswerVotersOptions {
channelId: Snowflake;
messageId: Snowflake;
answerId: number;
}
@@ -4422,7 +4421,7 @@ export abstract class MessageManager<InGuild extends boolean = boolean> extends
public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;
public pin(message: MessageResolvable, reason?: string): Promise<void>;
public unpin(message: MessageResolvable, reason?: string): Promise<void>;
public endPoll(channelId: Snowflake, messageId: Snowflake): Promise<Message>;
public endPoll(messageId: Snowflake): Promise<Message>;
public fetchPollAnswerVoters(options: FetchPollAnswerVotersOptions): Promise<Collection<Snowflake, User>>;
}

3 changes: 1 addition & 2 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -2549,9 +2549,8 @@ declare const poll: Poll;

expectType<Collection<Snowflake, User>>(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,
});

0 comments on commit 0474a43

Please sign in to comment.