feat(GroupDM): Add setOwner
, handle event update
Co-Authored-By: Nguyễn Hồng Đức <hongducyb123@gmail.com>
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
Reference in New Issue
Block a user