RoleTransformer
Expose a role to a template.
RoleTransformer reads an APIRole payload.
For template authors
Syntax
{{role}}
{{role(key)}}
{{role.key}}The bare tag renders the mention. A parameter picks one field.
Examples
The {role(name)} role sits at position {role(position)}.
# The Moderator role sits at position 16.Fields
| Key | Gives |
|---|---|
id | The role ID. |
mention | A role mention. |
name | The role name. |
color | The colour as a number in a string. |
hoist | Whether the role shows separately in the member list. |
mentionable | true or false. |
position | The position in the role list. |
permissions | The permission names, comma separated. |
createdAt | Creation date as an ISO string. |
createdTimestamp | Creation time in milliseconds. |
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 { RoleTransformer } from '@tagscript/plugin-discord';
import { Interpreter, StrictVarsParser } from 'tagscript';
const ts = new Interpreter(new StrictVarsParser());
const response = await ts.run(template, {
role: new RoleTransformer(role),
});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 RoleTransformer(role, {
custom: 'a fixed value',
computed: (base) => `${base.id} was looked up at render time`,
});A role payload does not say who holds the role, so count the members yourself if a template needs it:
new RoleTransformer(role, {
memberCount: members.filter((member) => member.roles.includes(role.id)).length,
});API reference
Last updated on