mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Partials (#3070)
* Remove GroupDMChannels they sparked no joy * Start partials for message deletion * MessageUpdate partials * Add partials as an opt-in client option * Add fetch() to Message * Message.author should never be undefined * Fix channels being the wrong type * Allow fetching channels * Refactor and add reaction add partials * Reaction remove partials * Check for emoji first * fix message fetching janky * User partials in audit logs * refactor overwrite code * guild member partials * partials as a whitelist * document GuildMember#fetch * fix: check whether a structure is a partial, not whether cache is true * typings: Updated for latest commit (#3075) * partials: fix messageUpdate behaviour (now "old" message can be partial) * partials: add warnings and docs * partials: add partials to index.yml * partials: tighten "partial" definitions * partials: fix embed-only messages counting as partials
This commit is contained in:
@@ -12,6 +12,8 @@ const MessageStore = require('../stores/MessageStore');
|
||||
class DMChannel extends Channel {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
// Override the channel type so partials have a known type
|
||||
this.type = 'dm';
|
||||
/**
|
||||
* A collection containing the messages sent to this channel
|
||||
* @type {MessageStore<Snowflake, Message>}
|
||||
@@ -23,11 +25,13 @@ class DMChannel extends Channel {
|
||||
_patch(data) {
|
||||
super._patch(data);
|
||||
|
||||
/**
|
||||
* The recipient on the other end of the DM
|
||||
* @type {User}
|
||||
*/
|
||||
this.recipient = this.client.users.add(data.recipients[0]);
|
||||
if (data.recipients) {
|
||||
/**
|
||||
* The recipient on the other end of the DM
|
||||
* @type {User}
|
||||
*/
|
||||
this.recipient = this.client.users.add(data.recipients[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The ID of the last message in the channel, if one was sent
|
||||
@@ -42,6 +46,14 @@ class DMChannel extends Channel {
|
||||
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this DMChannel is a partial
|
||||
* @type {boolean}
|
||||
*/
|
||||
get partial() {
|
||||
return !this.recipient;
|
||||
}
|
||||
|
||||
/**
|
||||
* When concatenated with a string, this automatically returns the recipient's mention instead of the
|
||||
* DMChannel object.
|
||||
|
||||
Reference in New Issue
Block a user