Skip to content
GitHub

EntityRef

interface in meocord/interface Since 4.1.0

interface EntityRef<T>

A member, user, role or channel a message command names, as its guards see it: not fetched yet.

Read cached for what discord.js already has, and call resolve() only once a cheaper check has passed, so a caller you refuse costs no request. The handler receives the entity itself, fetched after the guards.

Examples

TypeScript
@Guard()
export class OutranksTargetGuard implements GuardInterface {
  async canActivate(message: Message, { target }: ParamRefsOf<'ban {target:member}'>) {
    if (!message.member?.permissions.has('BanMembers')) return false
    const member = target.cached ?? (await target.resolve())
    return !member || member.roles.highest.position < message.member.roles.highest.position
  }
}

Members

id

readonly id: string

The entity's ID: the one the message gave, by mention or as a bare ID, or a role's found by its name.

cached

readonly cached: T | undefined

The entity when discord.js already has it, with no request; undefined otherwise.

resolve

resolve(): Promise<T | undefined>

Fetches the entity, once however many callers ask at the same time; undefined when there is none.

Returns

Promise<T | undefined>

See also