Tagscript

ChannelTransformer

Expose a guild channel to a template.

ChannelTransformer reads a guild channel payload, either a full APIGuildChannel or the trimmed one Discord puts in an interaction's resolved data. Fields that only some channel types have, such as topic and slowmode, fall back to an empty string or 0 rather than failing.

For template authors

Syntax

{{channel}}
{{channel(key)}}
{{channel.key}}

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

Examples

Please move this to {channel}.
# Please move this to <#870354581115256852>.

Fields

KeyGives
idThe channel ID.
mentionA channel link.
nameThe channel name.
topicThe topic, or empty.
typeThe channel type.
positionThe position in the channel list.
nsfwtrue or false.
parentIdThe category ID.
createdAtCreation date as an ISO string.
createdTimestampCreation time in milliseconds.
slowmodeSlowmode in seconds, or 0.

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

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

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

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

A channel payload carries parentId and nothing else about the category, so pass the category yourself if a template needs its name:

new ChannelTransformer(channel, { parentName: parent.name, parentType: parent.type });

API reference

ChannelTransformer

Last updated on

On this page

Edit on Github