feat(RoleStore, ChannelStore): fetch() method (#3071)

* feat({Role,Channel}Store): fetch method

* docs: Add usage examples to the new methods

* misc: Add note of why we are fetching all roles even for a single one
This commit is contained in:
Kyra
2019-02-09 16:07:31 +01:00
committed by Amish Shah
parent ae7269088b
commit c432591113
3 changed files with 49 additions and 0 deletions

View File

@@ -74,6 +74,24 @@ class ChannelStore extends DataStore {
super.remove(id);
}
/**
* Obtains a channel from Discord, or the channel cache if it's already available.
* @param {Snowflake} id ID of the channel
* @param {boolean} [cache=true] Whether to cache the new channel object if it isn't already
* @returns {Promise<Channel>}
* @example
* // Fetch a channel by its id
* client.channels.fetch('222109930545610754')
* .then(channel => console.log(channel.name))
* .catch(console.error);
*/
fetch(id, cache = true) {
const existing = this.get(id);
if (existing) return Promise.resolve(existing);
return this.client.api.channels(id).get().then(data => this.add(data, null, cache));
}
/**
* Data that can be resolved to give a Channel object. This can be:
* * A Channel object