Skip to content

Enhancement suggestion: Autofetch uncached data #1376

@Drahcirius

Description

@Drahcirius

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:

  1. MESSAGE_CREATE:
    • Previous behaviour:
      • User is added to cache
    • 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()
  2. 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
  3. 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.
  4. MESSAGE_REACTION_REMOVE
    • See MESSAGE_REACTION_ADD

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions