From 4ec46f014d0f6504d018a0f92c826c4364c8ba85 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Wed, 15 Jun 2022 18:15:33 +0700 Subject: [PATCH] feat(ClientUser): Add getMentions --- src/structures/ClientUser.js | 28 ++++++++++++++++++++++++++-- typings/index.d.ts | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 2e2ec30..e3f08bd 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -2,6 +2,7 @@ const { Collection } = require('@discordjs/collection'); const Invite = require('./Invite'); +const { Message } = require('./Message'); const User = require('./User'); const { Util } = require('..'); const { HypeSquadOptions, Opcodes, NitroState } = require('../util/Constants'); @@ -418,8 +419,8 @@ class ClientUser extends User { * @returns {Promise} * @see https://github.com/13-05/hidden-disc-docs#js-snippet-for-creating-friend-invites * @example - * // Create an invite to a selected channel - * client.user.getInvite({ maxAge: 0, maxUses: 0 }); + * // Options not working + * client.user.getInvite(); * .then(console.log) * .catch(console.error); */ @@ -435,6 +436,29 @@ class ClientUser extends User { }); 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>} + */ + 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; diff --git a/typings/index.d.ts b/typings/index.d.ts index 249733a..66e7e60 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -702,6 +702,7 @@ export class ClientUser extends User { public setDeaf(status: boolean): Promise; public setMute(status: boolean): Promise; public getInvite(options?: CreateInviteOptions): Promise; + public getMentions(limit?: number, mentionRoles?: boolean, mentionEveryone?: boolean): Promise>; /** * Nitro Status * `0`: None