Autofetch
7/6/2017 update
Add a new client setting, autofetch, with allowable values similar to the disabledEvents client setting.
const client = new Client({ autofetch: [
'MESSAGE_CREATE',
'MESSAGE_UPDATE',
'MESSAGE_REACTION_ADD',
'MESSAGE_REACTION_REMOVE',
] });
If a WS event is disabled through disabledEvents, then the respective autoFetch event will also be disabled, even if it is specified in this field.
Autofetch will do the following on the listed events:
- MESSAGE_CREATE:
- Previous behaviour:
- New Behaviour
- Check member cache for author and mentioned users. If members are not in cache, fetch guild members before emitting
message event.
- Use case
- Removes the need for users to manually call
<guild>.fetchMember() in every message event. The convenience property <message>.mentions.members is somewhat unreliable as it will return an empty collection when the member isn't in the cache. As an example, people using <message>.mentions.members.first().roles will receive an error because of trying to access a property on undefined . Most of the time, people fetch the member to prevent this issue, thereby making it redundant since you can use the member returned from the <guild>.fetchMember()
- MESSAGE_UPDATE:
- Previous behaviour
- If message is not in cache, do nothing. Otherwise, update message and emit
messageUpdate
- New Behaviour
- Cache message and emit
messageUpdate event. <message>.edits will be empty because the old message was not cached.
- Use case
- Bots that respond to commands when a message is edited may want to continue to do so even after a restart. With this enabled
- MESSAGE_REACTION_ADD:
- Previous Behaviour
- If message reacted to was not in cache, do nothing.
- New Behaviour
- If message that was reacted to was not previously in the cache, fetch the message and emit
messageReactionAdd event.
- Use case
- Many bots perform actions upon messages receiving a reaction, and currently the only way for bots to respond to reactions on older messages is to fetch all recent messages, or to store particular messages somewhere and fetch them individually after a restart. It may save bandwidth and memory if these messages were only fetched when a new reaction is added, instead of fetching to make sure it's in the cache, this way they can fetch only when necessary.
- MESSAGE_REACTION_REMOVE
The following events do not benefit from autofetch:
- MESSAGE_DELETE: event only contains ID, does not have message contents
- MESSAGE_DELETE_BULK: same as above
- MESSAGE_REACTION_REMOVE_ALL: same as above
- CHANNEL_*: received on login
- GUILD_*: received on login
- Other: Not applicable
Autofetch
7/6/2017 update
Add a new client setting, autofetch, with allowable values similar to the
disabledEventsclient setting.If a WS event is disabled through
disabledEvents, then the respective autoFetch event will also be disabled, even if it is specified in this field.Autofetch will do the following on the listed events:
messageevent.<guild>.fetchMember()in every message event. The convenience property<message>.mentions.membersis somewhat unreliable as it will return an empty collection when the member isn't in the cache. As an example, people using<message>.mentions.members.first().roleswill receive an error because of trying to access a property on undefined . Most of the time, people fetch the member to prevent this issue, thereby making it redundant since you can use the member returned from the<guild>.fetchMember()messageUpdatemessageUpdateevent.<message>.editswill be empty because the old message was not cached.messageReactionAddevent.The following events do not benefit from autofetch:
- MESSAGE_DELETE: event only contains ID, does not have message contents
- MESSAGE_DELETE_BULK: same as above
- MESSAGE_REACTION_REMOVE_ALL: same as above
- CHANNEL_*: received on login
- GUILD_*: received on login
- Other: Not applicable