Message

All of the things you type and send will be messages

Field

Field

Description

.Message.ID

ID of the message.

.Message.ChannelID

Channel ID this message is in.

.Message.GuildID

Guild ID in which the message is.

.Message.Content

Text content on this message.

.Message.Timestamp

Timestamp of the message in type discordgo.Timestamp (use .Message.Timestamp.Parse to get type time.Time and .Parse.String method returns type string).

.Message.EditedTimestamp

The time at which the last edit of the message occurred, if it has been edited.

.Message.MentionRoles

The roles mentioned in the message.

.Message.MentionEveryone

Whether the message mentions everyone.

.Message.Author

Author of the message (User object).

.Message.Attachments

Attachments to this message (slice of attachment objects).

.Message.Embeds

Embeds on this message (slice of embed objects).

.Message.Mentions

Users this message mentions.

.Message.Reactions

Reactions on this message (only available from getMessage).

.Message.Type

The type of the message.

.Message.Pinned

Whether this message is pinned.

.Args

List of everything that is passed to .Message.Content. .Args is a slice of type string. Example here.

.Cmd

.Cmd is of type string and shows all arguments that trigger custom command, part of .Args. Starting from {{index .Args 0}}. Example here.

.CmdArgs

List of all the arguments passed after .Cmd (.Cmd is the actual trigger) .CmdArgs is a slice of type string. Example here.

.StrippedMsg

"Strips" or cuts off the triggering part of the message and prints out everything else after that. Bear in mind, when using regex as trigger, for example "day" and input message is "Have a nice day my dear YAG!" output will be "my dear YAG!" - rest is cut off. Example here.

Example:

  • We will demonstrate .Args, .Cmd, .CmdArgs, and .StrippedMsg.

Now your whole trigger: -hello and you type in -hello the world.
.Args will returns: {{.Args}}, and it is of type {{printf "%T" .Args}}. Its length is {{len .Args}}.
.Cmd will returns: {{.Cmd}}, and it is of type {{printf "%T" .Cmd}}. Its length is {{len .Cmd}}.
.CmdArgs will returns: {{.CmdArgs}}, and it is of type {{printf "%T" .CmdArgs}}. Its length is {{len .CmdArgs}}.
.StrippedMsg will returns: {{.StrippedMsg}}, and it is of type {{printf "%T" .StrippedMsg}}. Its length is **{{len .StrippedMsg}}.
Index the .Args and .CmdArgs:
.Args: {{index .Args 0}} | {{index .Args 1}} | {{index .Args 2}}
.CmdArgs: {{index .CmdArgs 0}} | {{index .CmdArgs 1}}


The outputs of the command.

Message object in Discord documentation (read it if you want to write complex codes).

More Info

You can fetch a message by ID or use the trigger message and get some information about it. Message returns the following things that you can access with it:

Field

Type

.Message.ID

Int

.Message.ChannelID

Int

.Message.Author

.Message.Timestamp

String

.Message.Attachments

Array of Attachments

.Message.Embeds

Array of Embed

.Message.Mentions

Array of User Object

.Message.Reactions

Array of Reactions

.Message.Content

String

Attachment

Either starts with (index .Message.Attachments 0). or a variable with the attachment type.

Field

Type

Description

ID

Int

The ID of the attachment

URL

String

cdn.discordapp.com URL

ProxyURL

String

media.discordapp.com URL

Filename

String

Filename of the attachment

Width

Int

Width of the attachment (if image) in pixels

Height

Int

Height of the attachment (if image) in pixels

Size

Int

Size of the attachment in bytes

Reaction

Either starts with (index .Message.Reactions 0) or a variable with the reaction type.

Field

Type

Description

Count

Int

Times this emoji has been used to react

Emoji

The emoji used in the reaction

Emoji

Either starts with (index .Message.Reactions 0).Emoji or a variable of the reaction type.

Field

Type

Description

ID

Int

ID of the emoji

Name

String

Name of the emoji (if Unicode emoji this will be the emote)

Animated

Boolean

Whether the emoji is animated or not

There are more fields which can be used, but they are either obsolete or only used with Global Emotes. Example to fetch the name of the first reaction on a message provided through the getMessage template:

{{$message := getMessage nil (index .Args 1)}}
{{if $message}}
{{if $message.Reactions}}
Name of the first reaction: {{(index $message.Reactions 0).Emoji.Name}}
{{else}}No reactions on this message{{end}}
{{else}}Unknown message{{end}}

Last updated

Was this helpful?