mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
channel stuff (#1775)
* channel stuff * abstract channel creation * Update Channel.js * Update Channel.js * Update Channel.js * Update Guild.js * Update Constants.js * e
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
/**
|
||||
* Represents any channel on Discord.
|
||||
@@ -13,15 +14,17 @@ class Channel {
|
||||
*/
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
const type = Object.keys(Constants.ChannelTypes)[data.type];
|
||||
/**
|
||||
* The type of the channel, either:
|
||||
* * `dm` - a DM channel
|
||||
* * `group` - a Group DM channel
|
||||
* * `text` - a guild text channel
|
||||
* * `voice` - a guild voice channel
|
||||
* * `unknown` - a generic channel of unknown type, could be Channel or GuildChannel
|
||||
* @type {string}
|
||||
*/
|
||||
this.type = null;
|
||||
this.type = type ? type.toLowerCase() : 'unknown';
|
||||
|
||||
if (data) this.setup(data);
|
||||
}
|
||||
@@ -64,6 +67,37 @@ class Channel {
|
||||
delete() {
|
||||
return this.client.api.channels(this.id).delete().then(() => this);
|
||||
}
|
||||
|
||||
static create(client, data, guild) {
|
||||
const DMChannel = require('./DMChannel');
|
||||
const GroupDMChannel = require('./GroupDMChannel');
|
||||
const TextChannel = require('./TextChannel');
|
||||
const VoiceChannel = require('./VoiceChannel');
|
||||
const GuildChannel = require('./GuildChannel');
|
||||
const types = Constants.ChannelTypes;
|
||||
let channel;
|
||||
if (data.type === types.DM) {
|
||||
channel = new DMChannel(client, data);
|
||||
} else if (data.type === types.GROUP) {
|
||||
channel = new GroupDMChannel(client, data);
|
||||
} else {
|
||||
guild = guild || client.guilds.get(data.guild_id);
|
||||
if (guild) {
|
||||
switch (data.type) {
|
||||
case types.TEXT:
|
||||
channel = new TextChannel(guild, data);
|
||||
break;
|
||||
case types.VOICE:
|
||||
channel = new VoiceChannel(guild, data);
|
||||
break;
|
||||
default:
|
||||
channel = new GuildChannel(guild, data);
|
||||
}
|
||||
guild.channels.set(channel.id, channel);
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Channel;
|
||||
|
||||
Reference in New Issue
Block a user