feat(Partials): add DMChannel/MessageReaction#fetch() and Parti… (#3261)

* add DMChannel#fetch() & Action#getChannel({recipients})

* ref for MessageReaction partial

* typings

* add PartialTypes.REACTION

* accommodate for fully removed reactions

* fix incorrect wording and typo

* typings: MessageReaction#count is nullable

* typings: mark MessageReaction#partial as readonly

Co-Authored-By: Vlad Frangu <kingdgrizzle@gmail.com>

* fix(User): fetch dm channel if cached one is partial

* docs: add missing comma

Co-Authored-By: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
izexi
2019-09-10 15:09:06 +01:00
committed by Crawl
parent 6f83e71555
commit b0047c424b
9 changed files with 80 additions and 20 deletions

View File

@@ -9,8 +9,8 @@ discard the event. With partials, you're able to receive the event, with a Messa
Partials are opt-in, and you can enable them in the Client options by specifying [PartialTypes](../typedef/PartialType):
```js
// Accept partial messages and DM channels when emitting events
new Client({ partials: ['MESSAGE', 'CHANNEL'] });
// Accept partial messages, DM channels, and reactions when emitting events
new Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
```
## Usage & warnings
@@ -45,6 +45,10 @@ client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
// Now the message has been cached and is fully available:
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
// Fetches and caches the reaction itself, updating resources that were possibly defunct.
if (reaction.partial) await reaction.fetch();
// Now the reaction is fully available and the properties will be reflected accurately:
console.log(`${reaction.count} user(s) have given the same reaction this message!`);
});
```
@@ -58,4 +62,4 @@ bot or any bot that relies on still receiving updates to resources you don't hav
good example.
Currently, the only type of channel that can be uncached is a DM channel, there is no reason why guild channels should
not be cached.
not be cached.