Tagscript

UserTransformer

Expose a Discord user to a template.

UserTransformer reads an APIUser payload. The template gets the fields below and nothing else, so there is no path from a template to the client or to any method on the user.

For template authors

Syntax

{{user}}
{{user(key)}}
{{user.key}}

The bare tag renders the mention. A parameter picks one field.

Examples

Hi {user}, your account was made on {user(createdAt)}.
# Hi <@758880890159235083>, your account was made on 2020-09-25T10:11:12.000Z.

Fields

KeyGives
idThe user ID.
mentionA mention, the same as the bare tag.
nameEmpty, since a user payload has no name.
usernameThe username.
globalNameThe display name, or empty.
discriminatorThe legacy discriminator.
tagUsername and discriminator together, or just the username on a migrated account.
avatarThe custom avatar URL, or empty when they have none.
displayAvatarThe avatar URL, falling back to the default avatar.
createdAtAccount creation date as an ISO string.
createdTimestampAccount creation time in milliseconds.
bottrue or false.

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 { UserTransformer } from '@tagscript/plugin-discord';
import { Interpreter, StrictVarsParser } from 'tagscript';

const ts = new Interpreter(new StrictVarsParser());

const response = await ts.run(template, {
	user: new UserTransformer(message.author),
});

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 UserTransformer(user, {
	custom: 'a fixed value',
	computed: (base) => `${base.id} was looked up at render time`,
});

API reference

UserTransformer

Last updated on

On this page

Edit on Github