Skip to main content

Message Variables

Message variables are a way to dynamically adjust the content of your message based on the context. This is especially useful in responses to custom commands and interactive components.

To use a variable in your message just put {{ .VariableName }} where you want the value to appear. For example put {{ .Interaction.User.Mention }} in your message content to ping the user that has used a command. Please notice the dot (.) in front of each variable name!

Variables in Button Variables in response

List of Variables​

VariableTypeDescription
.Interaction.UsertextMention the user that has used the command or interactive component.
.Interaction.User.IDtextThe ID of the user that has used the command or interactive component.
.Interaction.User.NametextThe display name or username of the user that has used the command or interactive component.
.Interaction.User.UsernametextThe username of the user that has used the command or interactive component.
.Interaction.User.DiscriminatortextThe discriminator of the user that has used the command or interactive component.
.Interaction.User.AvatartextThe avatar hash of the user that has used the command or interactive component.
.Interaction.User.AvatarURLtextThe avatar URL of the user that has used the command or interactive component.
.Interaction.User.GlobalNametextThe display name of the user that has used the command or interactive component.
.Interaction.User.MentiontextMention the user that has used the command or interactive component.
.ServertextThe name of the server where the command or interactive component has been used.
.Server.IDtextThe ID of the server where the command or interactive component has been used.
.Server.NametextThe name of the server where the command or interactive component has been used.
.Server.DescriptiontextThe description of the server where the command or interactive component has been used.
.Server.IcontextThe icon hash of the server where the command or interactive component has been used.
.Server.IconURLtextThe icon URL of the server where the command or interactive component has been used.
.Server.BannertextThe banner hash of the server where the command or interactive component has been used.
.Server.BannerURLtextThe banner URL of the server where the command or interactive component has been used.
.Server.MemberCounttextThe approximate member count of the server where the command or interactive component has been used. (might be inaccurate)
.Server.BoostCounttextThe boost count of the server where the command or interactive component has been used.
.Server.BoostLeveltextThe boost level of the server where the command or interactive component has been used.
.ChanneltextMention the channel where the command or interactive component has been used.
.Channel.IDtextThe ID of the channel where the command or interactive component has been used.
.Channel.NametextThe name of the channel where the command or interactive component has been used.
.Channel.MentiontextMention the channel where the command or interactive component has been used.
.Channel.TopictextThe topic of the channel where the command or interactive component has been used.
.Interaction.CommandtextMention the command that was used.
.Interaction.Command.IDtextThe ID of the command that was used.
.Interaction.Command.NametextThe name of the command that was used.
.Interaction.Command.Args.my_argtext / user / channel / role / attachmentThe value of one of the command arguments. Replace my_arg with the name of the argument. Depending on the type of the command argument this might have sub variables like .Interaction.Command.Args.my_arg.ID for the id of a user.

Advanced Usage​

Under the hood message variables are powered by Go Templates which supports more than just basic variables. You can do if statements, loops, and a lot more!

Below there are some example of what you can do, but for more information pleae read the Go Template documentation.

Loop Example​

List the roles of the user that has used the custom command or interactive component:

{{ range .Interaction.User.Roles -}}
{{- .Mention -}}
{{- end }}

Notice the dot (., also known as cursor) encompasses all active data available for use in the templating system, in other words it always refers to current context. In the loop it refers to the current item, in this case one of the roles.

Also notice the dash (-) inside each of the actions which is used to strip all whitespaces from that side.

If-Else Example​

Check if the server has more than 5 boosts and respond based on it.

{{ if gt .Server.BoostCount 5 -}}
Your server has a lot of boosts!
{{- else -}}
Your server doesn't have a lot of boosts yet :(
{{- end }}

Notice the dash (-) inside each of the actions which is used to strip all whitespaces from that side.

Dates and Times​

currentTime is the time the message is sent, in UTC. In a scheduled message that is the time of each run. discordTimestamp turns a time into a Discord timestamp, which every viewer sees in their own timezone:

Sent {{ discordTimestamp currentTime "R" }}, the event starts {{ discordTimestamp (newDate 2026 10 2 18 0 0) "F" }}

The second argument is the style: t (16:20), T (16:20:30), d (20/04/2021), D (20 April 2021), f (20 April 2021 16:20), F (Tuesday, 20 April 2021 16:20) or R (2 months ago). Leave it out for f. newDate takes year, month, day, hour, minute and second in UTC. discordTimestamp also accepts a Unix timestamp in seconds.

Because Discord shows timestamps in the viewer's timezone, a date can land on a different day for some people. Midnight UTC on October 2 shows as October 1 for anyone in the Americas. To show the UTC date to everyone, format it as text instead:

{{ currentTime.Format "January 2, 2006" }}