feat(GroupDM): Add setOwner, handle event update

Co-Authored-By: Nguyễn Hồng Đức <hongducyb123@gmail.com>
This commit is contained in:
March 7th
2022-08-19 18:16:11 +07:00
parent e4567e9caf
commit 15f95626c6
4 changed files with 90 additions and 59 deletions

View File

@@ -3,9 +3,7 @@
const process = require('node:process');
const CachedManager = require('./CachedManager');
const { Channel } = require('../structures/Channel');
// Not used: const PartialGroupDMChannel = require('../structures/PartialGroupDMChannel');
const User = require('../structures/User');
const { Events, ThreadChannelTypes } = require('../util/Constants');
const { Events, ThreadChannelTypes, RelationshipTypes } = require('../util/Constants');
let cacheWarningEmitted = false;
@@ -119,19 +117,20 @@ class ChannelManager extends CachedManager {
this._remove(id);
return this._add(data, null, { cache, allowUnknownGuild });
}
// Create Group DM
/**
* Create Group DM
* @param {Array<Discord.User>} recipients Array of recipients
* @returns {PartialGroupDMChannel} Channel
* @param {UserResolvable[]} recipients Array of recipients
* @returns {Promise<PartialGroupDMChannel>} Channel
*/
async createGroupDM(recipients) {
// Check
if (!recipients || !Array.isArray(recipients)) throw new Error('No recipients || Invalid Type (Array)');
recipients = recipients.filter(r => r instanceof User && r.id && r.friend);
if (!Array.isArray(recipients)) throw new Error(`Expected an array of recipients (got ${typeof recipients})`);
recipients = recipients
.map(r => this.client.users.resolveId(r))
.filter(r => r && this.client.relationships.cache.get(r) == RelationshipTypes.FRIEND);
if (recipients.length < 2 || recipients.length > 9) throw new Error('Invalid Users length (2 - 9)');
const data = await this.client.api.users['@me'].channels.post({
data: { recipients: recipients.map(r => r.id) },
data: { recipients },
});
return this._add(data, null, { cache: true, allowUnknownGuild: true });
}