@@ -386,6 +386,36 @@ class MessageManager extends CachedManager {
|
|||||||
for (const message of data) messages.set(message.id, this._add(message, cache));
|
for (const message of data) messages.set(message.id, this._add(message, cache));
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ends a poll.
|
||||||
|
* @param {Snowflake} messageId The id of the message
|
||||||
|
* @returns {Promise<Message>}
|
||||||
|
*/
|
||||||
|
async endPoll(messageId) {
|
||||||
|
const message = await this.client.api.channels(this.channel.id).polls(messageId).expire.post();
|
||||||
|
return this._add(message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options used for fetching voters of an answer in a poll.
|
||||||
|
* @typedef {BaseFetchPollAnswerVotersOptions} FetchPollAnswerVotersOptions
|
||||||
|
* @param {Snowflake} messageId The id of the message
|
||||||
|
* @param {number} answerId The id of the answer
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the users that voted for a poll answer.
|
||||||
|
* @param {FetchPollAnswerVotersOptions} options The options for fetching the poll answer voters
|
||||||
|
* @returns {Promise<Collection<Snowflake, User>>}
|
||||||
|
*/
|
||||||
|
async fetchPollAnswerVoters({ messageId, answerId, after, limit }) {
|
||||||
|
const voters = await this.client.channels(this.channel.id).polls(messageId).answers(answerId).get({
|
||||||
|
query: { limit, after },
|
||||||
|
});
|
||||||
|
|
||||||
|
return voters.users.reduce((acc, user) => acc.set(user.id, this.client.users._add(user, false)), new Collection());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MessageManager;
|
module.exports = MessageManager;
|
||||||
|
|||||||
@@ -874,10 +874,11 @@ class Message extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Immediately ends the poll. You cannot end polls from other users.
|
* Immediately ends the poll. You cannot end polls from other users.
|
||||||
* @returns {Promise<RawMessage>}
|
* @returns {Promise<this>}
|
||||||
|
* @deprecated Using MessageManager#endPoll(messageId) instead
|
||||||
*/
|
*/
|
||||||
endPoll() {
|
endPoll() {
|
||||||
return this.client.api.channels(this.channel.id).polls(this.id).expire.post();
|
return this.channel.messages.endPoll(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -885,19 +886,16 @@ class Message extends Base {
|
|||||||
* @param {number} answerId Answer Id
|
* @param {number} answerId Answer Id
|
||||||
* @param {Snowflake} [afterUserId] Get users after this user ID
|
* @param {Snowflake} [afterUserId] Get users after this user ID
|
||||||
* @param {number} [limit=25] Max number of users to return (1-100, default 25)
|
* @param {number} [limit=25] Max number of users to return (1-100, default 25)
|
||||||
* @returns {Promise<{ users: Partial<RawUser> }>}
|
* @returns {Promise<Collection<Snowflake, User>>}
|
||||||
|
* @deprecated Using MessageManager#fetchPollAnswerVoters({ messageId, answerId, after, limit }) instead
|
||||||
*/
|
*/
|
||||||
getAnswerVoter(answerId, afterUserId, limit = 25) {
|
getAnswerVoter(answerId, afterUserId, limit = 25) {
|
||||||
return this.client.api
|
return this.channel.messages.fetchPollAnswerVoters({
|
||||||
.channels(this.channel.id)
|
messageId: this.id,
|
||||||
.polls(this.id)
|
answerId,
|
||||||
.answers(answerId)
|
after: afterUserId,
|
||||||
.get({
|
limit,
|
||||||
query: {
|
});
|
||||||
after: afterUserId,
|
|
||||||
limit,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
17
typings/index.d.ts
vendored
17
typings/index.d.ts
vendored
@@ -2098,12 +2098,14 @@ export class Message<Cached extends boolean = boolean> extends Base {
|
|||||||
public markRead(): Promise<void>;
|
public markRead(): Promise<void>;
|
||||||
public report(breadcrumbs: number[], elements?: object): Promise<{ report_id: Snowflake }>;
|
public report(breadcrumbs: number[], elements?: object): Promise<{ report_id: Snowflake }>;
|
||||||
public vote(...ids: number[]): Promise<void>;
|
public vote(...ids: number[]): Promise<void>;
|
||||||
public endPoll(): Promise<RawMessageData>;
|
/** @deprecated Using MessageManager#endPoll(messageId) instead */
|
||||||
|
public endPoll(): Promise<this>;
|
||||||
|
/** @deprecated Using MessageManager#fetchPollAnswerVoters({ messageId, answerId, after, limit }) instead */
|
||||||
public getAnswerVoter(
|
public getAnswerVoter(
|
||||||
answerId: number,
|
answerId: number,
|
||||||
afterUserId?: Snowflake,
|
afterUserId?: Snowflake,
|
||||||
limit?: number,
|
limit?: number,
|
||||||
): Promise<{ users: Partial<RawUserData> }>;
|
): Promise<Collection<Snowflake, User>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CallState extends Base {
|
export class CallState extends Base {
|
||||||
@@ -4381,6 +4383,15 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
|
|||||||
): Promise<GuildMember>;
|
): Promise<GuildMember>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BaseFetchPollAnswerVotersOptions {
|
||||||
|
after?: Snowflake;
|
||||||
|
limit?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FetchPollAnswerVotersOptions extends BaseFetchPollAnswerVotersOptions {
|
||||||
|
messageId: Snowflake;
|
||||||
|
answerId: number;
|
||||||
|
}
|
||||||
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
|
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
|
||||||
private constructor(channel: TextBasedChannel, iterable?: Iterable<RawMessageData>);
|
private constructor(channel: TextBasedChannel, iterable?: Iterable<RawMessageData>);
|
||||||
public channel: TextBasedChannel;
|
public channel: TextBasedChannel;
|
||||||
@@ -4398,6 +4409,8 @@ export class MessageManager extends CachedManager<Snowflake, Message, MessageRes
|
|||||||
public pin(message: MessageResolvable, reason?: string): Promise<void>;
|
public pin(message: MessageResolvable, reason?: string): Promise<void>;
|
||||||
public unpin(message: MessageResolvable, reason?: string): Promise<void>;
|
public unpin(message: MessageResolvable, reason?: string): Promise<void>;
|
||||||
public search(options: MessageSearchOptions): Promise<MessageSearchResult>;
|
public search(options: MessageSearchOptions): Promise<MessageSearchResult>;
|
||||||
|
public endPoll(messageId: Snowflake): Promise<Message>;
|
||||||
|
public fetchPollAnswerVoters(options: FetchPollAnswerVotersOptions): Promise<Collection<Snowflake, User>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MessageSearchOptions {
|
export interface MessageSearchOptions {
|
||||||
|
|||||||
Reference in New Issue
Block a user