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
| Key | Gives |
|---|---|
id | The user ID. |
mention | A mention, the same as the bare tag. |
name | Empty, since a user payload has no name. |
username | The username. |
globalName | The display name, or empty. |
discriminator | The legacy discriminator. |
tag | Username and discriminator together, or just the username on a migrated account. |
avatar | The custom avatar URL, or empty when they have none. |
displayAvatar | The avatar URL, falling back to the default avatar. |
createdAt | Account creation date as an ISO string. |
createdTimestamp | Account creation time in milliseconds. |
bot | true 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
Last updated on