mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
fix(Message): make #channel and #guild getters (#6271)
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,7 @@ class MessageCollector extends Collector {
|
||||
* @event MessageCollector#collect
|
||||
* @param {Message} message The message that was collected
|
||||
*/
|
||||
if (message.channel.id !== this.channel.id) return null;
|
||||
if (message.channelId !== this.channel.id) return null;
|
||||
this.received++;
|
||||
return message.id;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class MessageCollector extends Collector {
|
||||
* @event MessageCollector#dispose
|
||||
* @param {Message} message The message that was disposed of
|
||||
*/
|
||||
return message.channel.id === this.channel.id ? message.id : null;
|
||||
return message.channelId === this.channel.id ? message.id : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,8 +69,9 @@ class MessageMentions {
|
||||
this.roles = new Collection(roles);
|
||||
} else {
|
||||
this.roles = new Collection();
|
||||
const guild = message.guild;
|
||||
for (const mention of roles) {
|
||||
const role = message.channel.guild.roles.cache.get(mention);
|
||||
const role = guild.roles.cache.get(mention);
|
||||
if (role) this.roles.set(role.id, role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,9 +167,8 @@ class MessagePayload {
|
||||
|
||||
let message_reference;
|
||||
if (typeof this.options.reply === 'object') {
|
||||
const message_id = this.isMessage
|
||||
? this.target.channel.messages.resolveId(this.options.reply.messageReference)
|
||||
: this.target.messages.resolveId(this.options.reply.messageReference);
|
||||
const reference = this.options.reply.messageReference;
|
||||
const message_id = this.isMessage ? reference.id ?? reference : this.target.messages.resolveId(reference);
|
||||
if (message_id) {
|
||||
message_reference = {
|
||||
message_id,
|
||||
|
||||
@@ -63,7 +63,7 @@ class MessageReaction {
|
||||
*/
|
||||
async remove() {
|
||||
await this.client.api
|
||||
.channels(this.message.channel.id)
|
||||
.channels(this.message.channelId)
|
||||
.messages(this.message.id)
|
||||
.reactions(this._emoji.identifier)
|
||||
.delete();
|
||||
|
||||
@@ -176,7 +176,7 @@ class ReactionCollector extends Collector {
|
||||
* @returns {void}
|
||||
*/
|
||||
_handleChannelDeletion(channel) {
|
||||
if (channel.id === this.message.channel.id) {
|
||||
if (channel.id === this.message.channelId) {
|
||||
this.stop('channelDelete');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user