Tagscript

MemberTransformer

Expose a guild member to a template.

MemberTransformer reads an APIGuildMember payload, which is a user plus everything specific to one guild: nickname, roles, join date and timeout.

For template authors

Syntax

{{member}}
{{member(key)}}
{{member.key}}

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

Examples

Welcome {member}, you joined {date(R):{member(joinedTimestamp)}}.
# Welcome <@758880890159235083>, you joined <t:1642605059:R>.

Fields

KeyGives
idThe user ID.
mentionA mention.
nameEmpty, since a member payload has no name.
usernameThe username.
discriminatorThe legacy discriminator.
tagUsername and discriminator, or just the username on a migrated account.
avatarThe account avatar URL, or empty.
displayAvatarThe avatar URL, falling back to the default avatar.
nicknameThe guild nickname.
displayNameNickname if set, then global name, then username.
joinedAtJoin date as an ISO string.
joinedTimestampJoin time in milliseconds.
createdAtAccount creation date.
createdTimestampAccount creation time in milliseconds.
bottrue or false.
rolesA mention per role.
roleIdsThe role IDs.
timeoutUntilWhen a timeout ends.
timeoutUntilTimestampTimeout end 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 { MemberTransformer } from '@tagscript/plugin-discord';
import { Interpreter, StrictVarsParser } from 'tagscript';

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

const response = await ts.run(template, {
	member: new MemberTransformer(interaction.member),
});

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

A member payload lists role IDs and carries no guild ID, so role names, the top role, the member colour and the per-guild avatar all need the guild alongside the member. Work them out once and pass them in:

const roles = guild.roles.filter((role) => member.roles.includes(role.id));

new MemberTransformer(member, {
	roleNames: roles.map((role) => role.name).join(', '),
	topRole: roles.reduce((highest, role) => (role.position > highest.position ? role : highest)).name,
});

API reference

MemberTransformer

Last updated on

On this page

Edit on Github