Skip to content

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.

// Inside any handler or middleware
const user = await interaction.fetcher.users.get(userId);

new Fetcher(api, getCache): Fetcher

Defined in: utils/Fetcher.ts:20

Constructed internally by BaseInteraction — you do not construct this directly.

API

The raw @discordjs/core API instance. Use this for any Discord REST call not covered by the named accessors.

() => CacheManager | null | undefined

Fetcher

readonly api: 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.


readonly channels: 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.

string

Promise<CachedChannel>


readonly dmChannels: 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.

string

Promise<CachedDMChannel>


readonly guilds: 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.

string

Promise<APIGuild>


readonly members: 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.

string

string

Promise<APIGuildMember | CachedGuildMember>


readonly roles: 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.

string

string

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.

string

Promise<APIRole[]>


readonly users: 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.

string

Promise<APIUser>