mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix: Convert lastMessage to getters (#2384)
* convert lastMessage to getters * fix bug in pr * requested changes
This commit is contained in:
@@ -12,14 +12,13 @@ class MessageCreateAction extends Action {
|
||||
const user = message.author;
|
||||
const member = channel.guild ? channel.guild.member(user) : null;
|
||||
channel.lastMessageID = data.id;
|
||||
channel.lastMessage = message;
|
||||
if (user) {
|
||||
user.lastMessageID = data.id;
|
||||
user.lastMessage = message;
|
||||
user.lastMessageChannelID = channel.id;
|
||||
}
|
||||
if (member) {
|
||||
member.lastMessageID = data.id;
|
||||
member.lastMessage = message;
|
||||
member.lastMessageChannelID = channel.id;
|
||||
}
|
||||
|
||||
client.emit(Events.MESSAGE_CREATE, message);
|
||||
|
||||
@@ -44,6 +44,7 @@ class DMChannel extends Channel {
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
get lastMessage() {}
|
||||
send() {}
|
||||
search() {}
|
||||
startTyping() {}
|
||||
|
||||
@@ -220,6 +220,7 @@ class GroupDMChannel extends Channel {
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
get lastMessage() {}
|
||||
send() {}
|
||||
search() {}
|
||||
startTyping() {}
|
||||
|
||||
@@ -43,10 +43,10 @@ class GuildMember extends Base {
|
||||
this.lastMessageID = null;
|
||||
|
||||
/**
|
||||
* The Message object of the last message sent by the member in their guild, if one was sent
|
||||
* @type {?Message}
|
||||
* The ID of the channel for the last message sent by the member in their guild, if one was sent
|
||||
* @type {?Snowflake}
|
||||
*/
|
||||
this.lastMessage = null;
|
||||
this.lastMessageChannelID = null;
|
||||
}
|
||||
|
||||
_patch(data) {
|
||||
@@ -81,6 +81,16 @@ class GuildMember extends Base {
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Message object of the last message sent by the member in their guild, if one was sent
|
||||
* @type {?Message}
|
||||
* @readonly
|
||||
*/
|
||||
get lastMessage() {
|
||||
const channel = this.guild.channels.get(this.lastMessageChannelID);
|
||||
return (channel && channel.messages.get(this.lastMessageID)) || null;
|
||||
}
|
||||
|
||||
get voiceState() {
|
||||
return this._frozenVoiceState || this.guild.voiceStates.get(this.id) || {};
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ class TextChannel extends GuildChannel {
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
get lastMessage() {}
|
||||
send() {}
|
||||
search() {}
|
||||
startTyping() {}
|
||||
|
||||
@@ -59,10 +59,10 @@ class User extends Base {
|
||||
this.lastMessageID = null;
|
||||
|
||||
/**
|
||||
* The Message object of the last message sent by the user, if one was sent
|
||||
* @type {?Message}
|
||||
* The ID of the channel for the last message sent by the user, if one was sent
|
||||
* @type {?Snowflake}
|
||||
*/
|
||||
this.lastMessage = null;
|
||||
this.lastMessageChannelID = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +83,16 @@ class User extends Base {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Message object of the last message sent by the user, if one was sent
|
||||
* @type {?Message}
|
||||
* @readonly
|
||||
*/
|
||||
get lastMessage() {
|
||||
const channel = this.client.channels.get(this.lastMessageChannelID);
|
||||
return (channel && channel.messages.get(this.lastMessageID)) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The presence of this user
|
||||
* @type {Presence}
|
||||
|
||||
@@ -21,12 +21,15 @@ class TextBasedChannel {
|
||||
* @type {?Snowflake}
|
||||
*/
|
||||
this.lastMessageID = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Message object of the last message in the channel, if one was sent
|
||||
* @type {?Message}
|
||||
*/
|
||||
this.lastMessage = null;
|
||||
/**
|
||||
* The Message object of the last message in the channel, if one was sent
|
||||
* @type {?Message}
|
||||
* @readonly
|
||||
*/
|
||||
get lastMessage() {
|
||||
return this.messages.get(this.lastMessageID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,6 +337,7 @@ class TextBasedChannel {
|
||||
if (full) {
|
||||
props.push(
|
||||
'acknowledge',
|
||||
'lastMessage',
|
||||
'search',
|
||||
'bulkDelete',
|
||||
'startTyping',
|
||||
|
||||
Reference in New Issue
Block a user