mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
feat(PartialGroupDMChannel): to support Invite#channel for group dms (#3786)
* add PartialGroupDMChannel class * fix lint * add new errors * add new class to Channel.create * fix lint * update typings accordingly * better implement errors * remove unnecessary functions * oops * lint * lint * lint * more lint * more lint * jsdoc typo * suggested changes * i did not forget the typings
This commit is contained in:
@@ -94,6 +94,9 @@ const Messages = {
|
||||
REACTION_RESOLVE_USER: 'Couldn\'t resolve the user ID to remove from the reaction.',
|
||||
|
||||
VANITY_URL: 'This guild does not have the VANITY_URL feature enabled.',
|
||||
|
||||
DELETE_GROUP_DM_CHANNEL: 'Bots don\'t have access to Group DM Channels and cannot delete them',
|
||||
FETCH_GROUP_DM_CHANNEL: 'Bots don\'t have access to Group DM Channels and cannot fetch them',
|
||||
};
|
||||
|
||||
for (const [name, message] of Object.entries(Messages)) register(name, message);
|
||||
|
||||
@@ -96,9 +96,19 @@ class Channel extends Base {
|
||||
static create(client, data, guild) {
|
||||
const Structures = require('../util/Structures');
|
||||
let channel;
|
||||
if (data.type === ChannelTypes.DM || (data.type !== ChannelTypes.GROUP && !data.guild_id && !guild)) {
|
||||
const DMChannel = Structures.get('DMChannel');
|
||||
channel = new DMChannel(client, data);
|
||||
if (!data.guild_id && !guild) {
|
||||
switch (data.type) {
|
||||
case ChannelTypes.DM: {
|
||||
const DMChannel = Structures.get('DMChannel');
|
||||
channel = new DMChannel(client, data);
|
||||
break;
|
||||
}
|
||||
case ChannelTypes.GROUP: {
|
||||
const PartialGroupDMChannel = require('./PartialGroupDMChannel');
|
||||
channel = new PartialGroupDMChannel(client, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
guild = guild || client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
|
||||
46
src/structures/PartialGroupDMChannel.js
Normal file
46
src/structures/PartialGroupDMChannel.js
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const { Error } = require('../errors');
|
||||
|
||||
/**
|
||||
* Represents a Partial Group DM Channel on Discord.
|
||||
* @extends {Channel}
|
||||
*/
|
||||
class PartialGroupDMChannel extends Channel {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
|
||||
/**
|
||||
* The name of this Group DM Channel
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = data.name;
|
||||
|
||||
/**
|
||||
* The hash of the channel icon
|
||||
* @type {?string}
|
||||
*/
|
||||
this.icon = data.icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL to this channel's icon.
|
||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||
* @returns {?string}
|
||||
*/
|
||||
iconURL({ format, size } = {}) {
|
||||
if (!this.icon) return null;
|
||||
return this.client.rest.cdn.GDMIcon(this.id, this.icon, format, size);
|
||||
}
|
||||
|
||||
delete() {
|
||||
return Promise.reject(new Error('DELETE_GROUP_DM_CHANNEL'));
|
||||
}
|
||||
|
||||
fetch() {
|
||||
return Promise.reject(new Error('FETCH_GROUP_DM_CHANNEL'));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PartialGroupDMChannel;
|
||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -840,6 +840,13 @@ declare module 'discord.js' {
|
||||
public nsfw: boolean;
|
||||
}
|
||||
|
||||
export class PartialGroupDMChannel extends Channel {
|
||||
constructor(client: Client, data: object);
|
||||
public name: string;
|
||||
public icon: string | null;
|
||||
public iconURL(options?: ImageURLOptions): string | null;
|
||||
}
|
||||
|
||||
export class GuildEmoji extends Emoji {
|
||||
constructor(client: Client, data: object, guild: Guild);
|
||||
private _roles: string[];
|
||||
|
||||
Reference in New Issue
Block a user