DiscordPHP-MTG Documentation

InteractionTrait

What every module does with interactions: build its commands for every place the bot can be used, read option values, answer autocomplete, and reply after deferring — so a search that waits on the card build (or fails) still answers.

Tags
since
1.1.0

Table of Contents

Methods

answer()  : PromiseInterface
Answers a component click with a new message, or by replacing the clicked message, logging what fails.
choices()  : array<string|int, array{name: string, value: string}>
Autocomplete choices from `value => label` (or a list of values).
command()  : CommandBuilder
A chat command usable in servers, the bot's DMs and group DMs, from a server install or a user install.
failure()  : MessageBuilder
The message for a failure.
hidden()  : Option
The `hidden` option every command takes: reply only to the caller.
option()  : Option
A command option.
reply()  : PromiseInterface
Defers the reply, then answers with what `$work` resolves to. A failure answers too: a bad search is the caller's to fix, anything else is logged.
subcommand()  : Option
A sub-command with its options.
typed()  : array<string, mixed>
The values typed so far into the command being autocompleted, from inside its sub-command.
values()  : array<string, mixed>
Option values by name.

Methods

answer()

Answers a component click with a new message, or by replacing the clicked message, logging what fails.

protected static answer(MTG $mtg, Interaction $interaction, callable $work[, bool $update = false ]) : PromiseInterface
Parameters
$mtg : MTG
$interaction : Interaction
$work : callable

Returns a MessageBuilder or a promise of one.

$update : bool = false

Replace the clicked message instead of answering with a new, hidden one.

Return values
PromiseInterface

choices()

Autocomplete choices from `value => label` (or a list of values).

protected static choices(array<string|int, mixed> $choices) : array<string|int, array{name: string, value: string}>
Parameters
$choices : array<string|int, mixed>
Return values
array<string|int, array{name: string, value: string}>

command()

A chat command usable in servers, the bot's DMs and group DMs, from a server install or a user install.

protected static command(string $name, string $description) : CommandBuilder
Parameters
$name : string
$description : string
Return values
CommandBuilder

failure()

The message for a failure.

protected static failure(MTG $mtg, Throwable $e) : MessageBuilder
Parameters
$mtg : MTG
$e : Throwable
Return values
MessageBuilder

hidden()

The `hidden` option every command takes: reply only to the caller.

protected static hidden(MTG $mtg) : Option
Parameters
$mtg : MTG
Return values
Option

option()

A command option.

protected static option(MTG $mtg, int $type, string $name, string $description[, bool $required = false ][, bool $autocomplete = false ]) : Option
Parameters
$mtg : MTG
$type : int

An Option type constant.

$name : string
$description : string
$required : bool = false
$autocomplete : bool = false
Return values
Option

reply()

Defers the reply, then answers with what `$work` resolves to. A failure answers too: a bad search is the caller's to fix, anything else is logged.

protected static reply(MTG $mtg, Interaction $interaction, bool $hidden, callable $work) : PromiseInterface
Parameters
$mtg : MTG
$interaction : Interaction
$hidden : bool

Whether only the caller sees the answer.

$work : callable

Returns a MessageBuilder or a promise of one.

Return values
PromiseInterface

subcommand()

A sub-command with its options.

protected static subcommand(MTG $mtg, string $name, string $description, Option ...$options) : Option
Parameters
$mtg : MTG
$name : string
$description : string
$options : Option
Return values
Option

typed()

The values typed so far into the command being autocompleted, from inside its sub-command.

protected static typed(Interaction $interaction) : array<string, mixed>
Parameters
$interaction : Interaction
Return values
array<string, mixed>

values()

Option values by name.

protected static values(iterable<string|int, mixed> $options) : array<string, mixed>
Parameters
$options : iterable<string|int, mixed>

The options a command handler is given.

Return values
array<string, mixed>
On this page

Search results