Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MessageManager): poll methods don't need a channel id #10249

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/discord.js/src/managers/MessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 }),
});

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

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

export interface FetchPollAnswerVotersOptions extends BaseFetchPollAnswerVotersOptions {
channelId: Snowflake;
messageId: Snowflake;
answerId: number;
}
Expand All @@ -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>>;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down