Tagscript

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

KeyGives
idThe interaction ID.
nameThe command name.
mentionA clickable command mention.
applicationIdThe application ID.
channelIdThe channel ID.
guildIdThe guild ID.
commandIdThe command ID.
commandNameThe command name.
localeThe user's locale.
guildLocaleThe 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

InteractionTransformer

Last updated on

On this page

Edit on Github