feat(ClientUser): Add getMentions

This commit is contained in:
March 7th 2022-06-15 18:15:33 +07:00
parent 17a1a19f42
commit 4ec46f014d
2 changed files with 27 additions and 2 deletions

View File

@ -2,6 +2,7 @@
const { Collection } = require('@discordjs/collection'); const { Collection } = require('@discordjs/collection');
const Invite = require('./Invite'); const Invite = require('./Invite');
const { Message } = require('./Message');
const User = require('./User'); const User = require('./User');
const { Util } = require('..'); const { Util } = require('..');
const { HypeSquadOptions, Opcodes, NitroState } = require('../util/Constants'); const { HypeSquadOptions, Opcodes, NitroState } = require('../util/Constants');
@ -418,8 +419,8 @@ class ClientUser extends User {
* @returns {Promise<Invite>} * @returns {Promise<Invite>}
* @see https://github.com/13-05/hidden-disc-docs#js-snippet-for-creating-friend-invites * @see https://github.com/13-05/hidden-disc-docs#js-snippet-for-creating-friend-invites
* @example * @example
* // Create an invite to a selected channel * // Options not working
* client.user.getInvite({ maxAge: 0, maxUses: 0 }); * client.user.getInvite();
* .then(console.log) * .then(console.log)
* .catch(console.error); * .catch(console.error);
*/ */
@ -435,6 +436,29 @@ class ClientUser extends User {
}); });
return new Invite(this.client, data); return new Invite(this.client, data);
} }
/**
* Get a collection of messages mentioning clientUser
* @param {number} [limit=25] Maximum number of messages to get
* @param {boolean} [mentionRoles=true] Whether or not to mention roles
* @param {boolean} [mentionEveryone=true] Whether or not to mention `@everyone`
* @returns {Promise<Collection<Snowflake, Message>>}
*/
async getMentions(limit = 25, mentionRoles = true, mentionEveryone = true) {
// https://canary.discord.com/api/v9/users/@me/mentions?limit=25&roles=true&everyone=true
const data = await this.client.api.users['@me'].mentions.get({
query: {
limit,
roles: mentionRoles,
everyone: mentionEveryone,
},
});
const collection = new Collection();
for (const msg of data) {
collection.set(msg.id, new Message(this.client, msg));
}
return collection;
}
} }
module.exports = ClientUser; module.exports = ClientUser;

1
typings/index.d.ts vendored
View File

@ -702,6 +702,7 @@ export class ClientUser extends User {
public setDeaf(status: boolean): Promise<boolean>; public setDeaf(status: boolean): Promise<boolean>;
public setMute(status: boolean): Promise<boolean>; public setMute(status: boolean): Promise<boolean>;
public getInvite(options?: CreateInviteOptions): Promise<Invite>; public getInvite(options?: CreateInviteOptions): Promise<Invite>;
public getMentions(limit?: number, mentionRoles?: boolean, mentionEveryone?: boolean): Promise<Collection<Snowflake, Message>>;
/** /**
* Nitro Status * Nitro Status
* `0`: None * `0`: None