Tagscript

GuildTransformer

Expose a guild to a template.

GuildTransformer reads an APIGuild payload, including the roles it ships with and a few counts derived from them.

For template authors

Syntax

{{guild}}
{{guild(key)}}
{{guild.key}}

The bare tag renders the guild name. A parameter picks one field.

Examples

Welcome to {guild}, owned by <@{guild(ownerId)}>.
# Welcome to My Server, owned by <@938716130720235601>.

Fields

KeyGives
idThe guild ID.
nameThe guild name.
descriptionThe guild description.
iconThe icon.
splashThe invite splash.
bannerThe banner.
featuresThe guild features.
ownerIdThe owner ID.
createdAtCreation date as an ISO string.
createdTimestampCreation time in milliseconds.
memberCountThe approximate member count, when the payload was fetched with counts.
rolesA mention per role.
roleIdsThe role IDs.
roleNamesThe role names.
roleCountHow many roles.
emojiCountHow many emojis.
stickerCountHow many stickers.
afkTimeoutThe AFK timeout.
afkChannelA mention of the AFK channel.
verificationLevelThe verification level.

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

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

const response = await ts.run(template, {
	guild: new GuildTransformer(guild),
});

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

Channels are a separate endpoint and are not part of a guild payload, and memberCount reads approximate_member_count, which Discord only sends when you fetch the guild with with_counts. Pass what you have:

new GuildTransformer(guild, {
	channelCount: channels.length,
	channelNames: channels.map((channel) => channel.name).join(', '),
	memberCount: cachedMemberCount,
});

API reference

GuildTransformer

Last updated on

On this page

Edit on Github