Fetcher
Class: Fetcher
Section titled “Class: Fetcher”Defined in: utils/Fetcher.ts:18
Cache-first REST wrapper available on every interaction object as interaction.fetcher. Checks
the CacheManager before making a live Discord API request, and writes the result back to the
cache automatically. If no cache adapter is configured, bypasses the cache and always fetches
from the API.
Example
Section titled “Example”// Inside any handler or middlewareconst user = await interaction.fetcher.users.get(userId);Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Fetcher(
api,getCache):Fetcher
Defined in: utils/Fetcher.ts:20
Constructed internally by BaseInteraction — you do not construct this directly.
Parameters
Section titled “Parameters”API
The raw @discordjs/core API instance. Use this for any Discord REST call not covered by the named accessors.
getCache
Section titled “getCache”() => CacheManager | null | undefined
Returns
Section titled “Returns”Fetcher
Properties
Section titled “Properties”
readonlyapi:API
Defined in: utils/Fetcher.ts:22
The raw @discordjs/core API instance. Use this for any Discord REST call not covered by the named accessors.
channels
Section titled “channels”
readonlychannels:object
Defined in: utils/Fetcher.ts:60
Cache-first accessor for channels.
get: (
channelId) =>Promise<CachedChannel>
Fetches a channel by ID. Returns the cached value if available, otherwise fetches from Discord and caches the result.
Parameters
Section titled “Parameters”channelId
Section titled “channelId”string
Returns
Section titled “Returns”Promise<CachedChannel>
dmChannels
Section titled “dmChannels”
readonlydmChannels:object
Defined in: utils/Fetcher.ts:71
Cache-first accessor for DM channels.
get: (
userId) =>Promise<CachedDMChannel>
Fetches a DM channel for a user. Returns the cached value if available, otherwise creates a new DM channel via Discord and caches the result.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<CachedDMChannel>
guilds
Section titled “guilds”
readonlyguilds:object
Defined in: utils/Fetcher.ts:82
Cache-first accessor for guilds.
get: (
guildId) =>Promise<APIGuild>
Fetches a guild by ID. Returns the cached value if available, otherwise fetches from Discord and caches the result.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
Returns
Section titled “Returns”Promise<APIGuild>
members
Section titled “members”
readonlymembers:object
Defined in: utils/Fetcher.ts:115
Cache-first accessor for guild members.
get: (
guildId,userId) =>Promise<APIGuildMember|CachedGuildMember>
Fetches a guild member by user ID. Returns the cached value if available, otherwise fetches from Discord and caches the result.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<APIGuildMember | CachedGuildMember>
readonlyroles:object
Defined in: utils/Fetcher.ts:93
Cache-first accessor for roles.
get: (
guildId,roleId) =>Promise<APIRole>
Fetches a single role. If not cached, fetches all roles for the guild via guilds.getRoles and returns the matching one.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
roleId
Section titled “roleId”string
Returns
Section titled “Returns”Promise<APIRole>
list: (
guildId) =>Promise<APIRole[]>
Fetches all roles for a guild. Returns cached roles if available (via CacheManager.getGuildRoles), otherwise fetches from Discord and bulk-caches the result.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
Returns
Section titled “Returns”Promise<APIRole[]>
readonlyusers:object
Defined in: utils/Fetcher.ts:49
Cache-first accessor for users.
get: (
userId) =>Promise<APIUser>
Fetches a user by ID. Returns the cached value if available, otherwise fetches from Discord and caches the result.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<APIUser>
