InteractionTransformer
Expose a slash command interaction to a template.
InteractionTransformer reads an APIApplicationCommandInteraction payload, which lets a template say which command was used and where.
For template authors
Syntax
{{command}}
{{command(key)}}
{{command.key}}The bare tag renders a command mention, which Discord turns into a clickable /ping in the client. A parameter picks one field.
Examples
You used the {command(commandName)} command.
# You used the ping command.
Run {command} again to try.
# Run </ping:938716130720235601> again to try.Fields
| Key | Gives |
|---|---|
id | The interaction ID. |
name | The command name. |
mention | A clickable command mention. |
applicationId | The application ID. |
channelId | The channel ID. |
guildId | The guild ID. |
commandId | The command ID. |
commandName | The command name. |
locale | The user's locale. |
guildLocale | The guild's locale. |
A key that does not exist leaves the tag in the output as written, so a typo is visible rather than silent.
For developers
Seeding one
import { InteractionTransformer } from '@tagscript/plugin-discord';
import { Interpreter, StrictVarsParser } from 'tagscript';
const ts = new Interpreter(new StrictVarsParser());
const response = await ts.run(template, {
command: new InteractionTransformer(interaction),
});A variable parser has to be registered for the tag to resolve.
Adding your own fields
Pass a second argument to expose extra keys. A function receives the payload and runs when the tag renders.
new InteractionTransformer(interaction, {
custom: 'a fixed value',
computed: (base) => `${base.id} was looked up at render time`,
});To expose the options a user passed to the command, use resolveCommandOptions instead.
API reference
Last updated on