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.