fix(Message): make #channel and #guild getters (#6271)

This commit is contained in:
Souji
2021-08-04 22:47:32 +02:00
committed by GitHub
parent 5b0621fb3a
commit 6e3236ab64
11 changed files with 41 additions and 25 deletions

View File

@@ -27,16 +27,21 @@ class Message extends Base {
/**
* @param {Client} client The instantiating client
* @param {APIMessage} data The data for the message
* @param {TextBasedChannels} channel The channel the message was sent in
*/
constructor(client, data, channel) {
constructor(client, data) {
super(client);
/**
* The channel that the message was sent in
* @type {TextBasedChannels}
* The id of the channel the message was sent in
* @type {Snowflake}
*/
this.channel = channel;
this.channelId = data.channel_id;
/**
* The id of the guild the message was sent in, if any
* @type {?Snowflake}
*/
this.guildId = data.guild_id ?? null;
/**
* Whether this message has been deleted
@@ -299,7 +304,7 @@ class Message extends Base {
}
if (data.referenced_message) {
this.channel.messages._add(data.referenced_message);
this.channel?.messages._add(data.referenced_message);
}
/**
@@ -333,6 +338,15 @@ class Message extends Base {
return clone;
}
/**
* The channel that the message was sent in
* @type {TextChannel|DMChannel|NewsChannel|ThreadChannel}
* @readonly
*/
get channel() {
return this.client.channels.resolve(this.channelId);
}
/**
* Whether or not this message is a partial
* @type {boolean}
@@ -376,7 +390,7 @@ class Message extends Base {
* @readonly
*/
get guild() {
return this.channel.guild ?? null;
return this.client.guilds.resolve(this.guildId);
}
/**
@@ -396,7 +410,7 @@ class Message extends Base {
* @readonly
*/
get thread() {
return this.channel.threads.resolve(this.id);
return this.channel?.threads.resolve(this.id) ?? null;
}
/**
@@ -405,7 +419,7 @@ class Message extends Base {
* @readonly
*/
get url() {
return `https://discord.com/channels/${this.guild ? this.guild.id : '@me'}/${this.channel.id}/${this.id}`;
return `https://discord.com/channels/${this.guildId ?? '@me'}/${this.channelId}/${this.id}`;
}
/**