feat: allows to create a group without user

This commit is contained in:
Elysia
2024-07-28 16:39:16 +07:00
parent 78977df08b
commit 772739f980
2 changed files with 6 additions and 5 deletions

View File

@@ -118,16 +118,17 @@ class ChannelManager extends CachedManager {
/** /**
* Create Group DM * Create Group DM
* @param {UserResolvable[]} recipients Array of recipients * @param {UserResolvable[]} [recipients=[]] Array of recipients
* @returns {Promise<GroupDMChannel>} Channel * @returns {Promise<GroupDMChannel>} Channel
* @example
* client.channels.createGroupDM();
*/ */
async createGroupDM(recipients) { async createGroupDM(recipients = []) {
// Check
if (!Array.isArray(recipients)) throw new Error(`Expected an array of recipients (got ${typeof recipients})`); if (!Array.isArray(recipients)) throw new Error(`Expected an array of recipients (got ${typeof recipients})`);
recipients = recipients recipients = recipients
.map(r => this.client.users.resolveId(r)) .map(r => this.client.users.resolveId(r))
.filter(r => r && this.client.relationships.cache.get(r) == RelationshipTypes.FRIEND); .filter(r => r && this.client.relationships.cache.get(r) == RelationshipTypes.FRIEND);
if (recipients.length <= 0 || recipients.length > 9) throw new Error('Invalid Users length (1 - 9)'); if (recipients.length > 9) throw new Error('Invalid Users length (max=9)');
const data = await this.client.api.users['@me'].channels.post({ const data = await this.client.api.users['@me'].channels.post({
data: { recipients }, data: { recipients },
}); });

2
typings/index.d.ts vendored
View File

@@ -3997,7 +3997,7 @@ export class BaseGuildEmojiManager extends CachedManager<Snowflake, GuildEmoji,
export class ChannelManager extends CachedManager<Snowflake, AnyChannel, ChannelResolvable> { export class ChannelManager extends CachedManager<Snowflake, AnyChannel, ChannelResolvable> {
private constructor(client: Client, iterable: Iterable<RawChannelData>); private constructor(client: Client, iterable: Iterable<RawChannelData>);
public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<AnyChannel | null>; public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<AnyChannel | null>;
public createGroupDM(recipients: UserResolvable[]): Promise<GroupDMChannel>; public createGroupDM(recipients?: UserResolvable[]): Promise<GroupDMChannel>;
} }
export class RelationshipManager extends BaseManager { export class RelationshipManager extends BaseManager {