Tagscript

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

KeyGives
idThe role ID.
mentionA role mention.
nameThe role name.
colorThe colour as a number in a string.
hoistWhether the role shows separately in the member list.
mentionabletrue or false.
positionThe position in the role list.
permissionsThe permission names, comma separated.
createdAtCreation date as an ISO string.
createdTimestampCreation 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

RoleTransformer

Last updated on

On this page

Edit on Github