DiscordPHP-NHA Documentation

ActorTrait

Resolves the {@see AgentContext} a dual-mode command runs as.

The consuming class must expose a StateStore $state property. Every command entry point that can act either as the caller or as the bot funnels its "whose agent?" selector through actor(), so the choice lives in exactly one place.

Tags
since
3.0.0

Table of Contents

Methods

actor()  : AgentContext
Works out who an action runs as.
requireDefaultAgent()  : int
The bot's default agent id, or a {@see \RuntimeException} when none is set.

Methods

actor()

Works out who an action runs as.

public actor(string|null $discord_user_id[, string|int|null $as = null ]) : AgentContext

With $as === null (the default) it is the invoking Discord user's own linked agent. $as overrides that:

  • "bot" / "default" / "self" → the bot's default agent;
  • a numeric string or int → that agent id, using the bot token.

When the caller has no linked agent and gave no override, it falls back to the bot's default agent if one exists.

Parameters
$discord_user_id : string|null

The invoking user's id, or null for a bot-only entry point.

$as : string|int|null = null

Selector, usually straight from a slash-command option.

Tags
throws
RuntimeException

When nothing can be acted as.

Return values
AgentContext

requireDefaultAgent()

The bot's default agent id, or a {@see \RuntimeException} when none is set.

private requireDefaultAgent() : int
Return values
int
On this page

Search results