You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Templating system uses standard ASCII quotation marks:
23
-
`"` for straight double quotes, `'` for apostrophes or single quotes and`` ` `` for backticks/back quotes; so make
17
+
`"` for straight double quotes, `'` for apostrophes or single quotes and`` ` `` for backticks/back quotes; so make
24
18
sure no "smart-quotes" are being used.
25
19
26
20
The difference between back quotes and double quotes in string literals is covered in
@@ -65,11 +59,11 @@ declared, or to the end of custom command if there are no control structures - c
65
59
A powerful component of templates is the ability to stack actions - like function calls, together - chaining one after
66
60
another. This is done by using pipes `|`. Borrowed from Unix pipes, the concept is simple: each pipeline’s output
67
61
becomes the input of the following pipe. One limitation of the pipes is that they can only work with a single value and
68
-
that value becomes the last parameter of the next pipeline.\
69
-
\
62
+
that value becomes the last parameter of the next pipeline.
63
+
70
64
**Example**: `{{randInt 41| add 2}}` would pipeline`randInt` function's return to addition `add` as second parameter
71
65
and it would be added to 2; this more simplified would be like `{{40| add 2}}` with return 42. If written normally, it
72
-
would be `{{ add 2 (randInt 41) }}`. Same pipeline but using a variable is also useful one -`{{$x:=40| add 2}}` would
66
+
would be `{{ add 2 (randInt 41) }}`. Same pipeline but using a variable is also useful one -`{{$x:=40| add 2}}` would
73
67
not return anything as printout, 40 still goes through pipeline to addition and 42 is stored to variable `$x` whereas
74
68
`{{($x:=40)| add 2}}` would return 42 and store 40 to `$x`.
75
69
@@ -84,7 +78,7 @@ overused**. In most cases, pipes are unnecessary and cause a dip in readability
84
78
85
79
Context data refers to information accessible via the dot, `{{ . }}`. The accessible data ranges from useful constants
86
80
to information regarding the environment in which the custom command was executed, such as the user that ran it, the
87
-
channel it was ran in, and so on.
81
+
channel it was run in, and so on.
88
82
89
83
Fields documented as accessible on specific structures, like the context user `.User`, are usable on all values that
90
84
share the same type. That is, given a user `$user`, `$user.ID` is a valid construction that yields the ID of the user.
@@ -162,7 +156,7 @@ Similarly, provided a channel `$channel`, `$channel.Name` gives the name of the
162
156
| .Guild.OwnerID | Outputs the ID of the owner. |
163
157
| .Guild.PreferredLocale | The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US" |
164
158
| .Guild.Roles | Outputs all roles and indexing them gives more information about the role. For example `{{len .Guild.Roles}}` gives you how many roles are there in that guild. Role struct has [following fields](https://discordapp.com/developers/docs/topics/permissions#role-object). |
165
-
| .Guild.Stickers | A slice of all [sticker objects] in the guild. |
159
+
| .Guild.Stickers | A slice of all [sticker objects] in the guild. |
166
160
| .Guild.Splash | Outputs the [splash hash](https://discordapp.com/developers/docs/reference#image-formatting) ID of the guild's splash. |
167
161
| .Guild.SystemChannelID | The ID of the channel where guild notices such as welcome messages and boost events are posted. |
168
162
| .Guild.Threads | Returns all active threads in the guild as a slice of type _\[]dstate.ChannelState_. |
@@ -253,7 +247,7 @@ Interaction functions are covered [here](/docs/reference/templates/functions#int
253
247
| .Message.ChannelID | Channel ID this message is in. |
254
248
| .Message.Components | Slice of [discordgo.ActionsRow](https://discord.com/developers/docs/interactions/message-components#action-rows)s, which each contain components. Example on indexing the first button or menu under a message: `( index ( index .Message.Components 0 ).Components 0 )`|
255
249
| .Message.Content | Text content of this message. |
256
-
| .Message.ContentWithMentionsReplaced | Replaces all <@ID> mentions with the username of the mention. |
250
+
| .Message.ContentWithMentionsReplaced | Replaces all `<@ID>` mentions with the username of the mention. |
257
251
| .Message.EditedTimestamp | The time at which the last edit of the message occurred, if it has been edited. As with .Message.Timestamp, it is of type _discordgo.Timestamp._|
258
252
| .Message.Embeds | Embeds of this message (_slice_ of embed objects). |
259
253
| .Message.Flags | Message flags, represented as a bit set. |
@@ -303,7 +297,7 @@ This is available and part of the dot when reaction trigger type is used.
303
297
| .ReactionAdded | Returns a boolean type _bool_ true/false indicating whether reaction was added or removed. |
304
298
| .ReactionMessage | Returns the message object reaction was added to. Not all regular .Message fields are filled though e.g. .Member. `{{range .ReactionMessage.Reactions}}`<br>`{{.Count}} - {{.Emoji.Name}}` <br>`{{end}}`Returns emoji count and their name.Has an alias `.Message` and it works the same way. |
305
299
306
-
[Reaction object in Discord documentation](https://discordapp.com/developers/docs/resources/message#reaction-object).\
300
+
[Reaction object in Discord documentation](https://discordapp.com/developers/docs/resources/message#reaction-object).
307
301
[Emoji object in Discord documentation.](https://discord.com/developers/docs/resources/emoji)
308
302
309
303
### User
@@ -356,7 +350,7 @@ to `eq`.
356
350
357
351
Comparison operators always require the same type: i.e comparing `1.23` and `1` would throw **`incompatible types for
358
352
comparison`** error as they are not the same type (one is float, the other int). To fix this, you should convert both to
359
-
the same type -> for example, `toFloat 1`.
353
+
the same type, for example, `toFloat 1`.
360
354
361
355
{{< /callout >}}
362
356
@@ -399,17 +393,18 @@ if one wishes to skip all remaining iterations, the `{{break}}` action may be us
399
393
400
394
{{< /callout >}}
401
395
402
-
Affected dot inside `range` is important because methods mentioned above in this documentation:`.Server.ID`,
403
-
`.Message.Content` etc are all already using the dot on the pipeline and if they are not carried over to the `range`
404
-
control structure directly, these fields do not exists and template will error out. Getting those values inside `range`
405
-
and also `with` action would need `$.User.ID` for example.\
406
-
\
396
+
Affected dot inside `range` is important because methods mentioned above in this documentation like `.Server.ID`,
397
+
are all already using the dot on the pipeline and if they are not carried over to the `range` control structure
398
+
directly, these fields do not necessarily exists and template will error out. Getting those values inside `range`
399
+
and also `with` action would need to use the global syntax (e.g. `$.Server.ID`).
400
+
407
401
`range` on slices/arrays provides both the index and element for each entry; `range` on map iterates over key/element
408
402
pairs. If a `range` action initializes a variable, that variable is set to the successive elements of the iteration.
409
403
`range` can also declare two variables, separated by a comma and set by index and element or key and element pair. In
410
-
case of only one variable, it is assigned the element.\
411
-
\
412
-
Like `if`, `range`is concluded with`{{end}}`action and declared variable scope inside `range` extends to that point.\
404
+
case of only one variable, it is assigned the element.
405
+
406
+
Like `if`, `range` is concluded with the `{{end}}` action and declared variable scope inside `range` extends to that
407
+
point.
413
408
414
409
```yag
415
410
{{/* range over an integer */}}
@@ -441,7 +436,7 @@ Hello!
441
436
```
442
437
443
438
This program iterates ten *thousand* times, adding a newline and a tab character on every iteration to the output---we
444
-
can fix this error by telling the bot to throw away (or "strip") whitespace characters by using the trim indicator `-`:
439
+
can fix this error by telling the bot to throw away (or "strip") whitespace characters by using the trim indicator `-`.
445
440
446
441
```yag
447
442
{{ range 10000 }}
@@ -467,10 +462,10 @@ Similar to an `if` action with an associated `else` branch, the `try`-`catch` co
467
462
`try` branch and the `catch` branch. First, the code in the `try` branch is ran, and if an error is raised by a function
468
463
during execution, the `catch` branch is executed instead with the context (`.`) set to the offending error.
469
464
470
-
To check for a specific error, one can compare the result of the `Error` method with a predetermined message. (For
465
+
To check for a specific error, one can compare the result of the `Error` method with a predetermined message. For
471
466
context, all errors have a method `Error` which is specified to return a message describing the reason that the error
472
-
was thrown.) For example, the following example has different behavior depending on whether "Reaction blocked" is in the
473
-
message of the error caught.
467
+
was thrown. The following example has different behavior depending on whether "Reaction blocked" is in the message of
468
+
the error caught.
474
469
475
470
```yag
476
471
{{ try }}
@@ -520,8 +515,8 @@ appropriate effect, like in a `range` action.
520
515
521
516
`with` lets you assign and carry pipeline value with its type as a dot (`.`) inside that control structure, it's like a
522
517
shorthand. If the value of the pipeline is empty, dot is unaffected and when an `else` or `else if` action is used,
523
-
execution moves on to those branches instead, similar to the `if` action.\
524
-
\
518
+
execution moves on to those branches instead, similar to the `if` action.
519
+
525
520
Affected dot inside `with` is important because methods mentioned above in this documentation:`.Server.ID`,
526
521
`.Message.Content` etc are all already using the dot on the pipeline and if they are not carried over to the `with`
527
522
control structure directly, these fields do not exists and template will error out. Getting those values inside `with`
@@ -570,7 +565,7 @@ To define an associated template, use the `define` action. It has the following
570
565
571
566
{{< callout context="danger" title="Danger: Associated Templates at Top Level" icon="outline/alert-octagon" >}}
572
567
573
-
**Warning:**Template definitions must be at the top level of the custom command program; in other words, they cannot be
568
+
Template definitions must be at the top level of the custom command program; in other words, they cannot be
574
569
nested in other actions (for example, an if action.) That is, the following custom command is invalid:
575
570
576
571
```yag
@@ -630,7 +625,7 @@ will result in execution of the custom command being stopped at the point the `r
630
625
631
626
### Execution
632
627
633
-
To execute a custom command, one of three methods may be used: `template`, `block`, or `execTemplate`.
628
+
To execute an associated template, one of three methods may be used: `template`, `block`, or `execTemplate`.
634
629
635
630
#### Template action
636
631
@@ -661,7 +656,7 @@ Below is an example of the `template` action in action:
661
656
{{ template "sayHi" "YAG" }} {{/* hi there, YAG */}}
662
657
```
663
658
664
-
Trim markers: `{{- ... -}}`were used in above example because whitespace is considered as part of output for associated
659
+
Trim markers: `{{- ... -}}`were used in above example because whitespace is considered as part of output for associated
665
660
template definitions (and actions in general).
666
661
667
662
#### Block action
@@ -830,13 +825,13 @@ You can have max 50 \* user_count (or 500 \* user_count for premium) values in t
830
825
new write functions will fail, this value is also cached, so it won't be detected immediately when you go above nor
831
826
immediately when you're under again.
832
827
833
-
Patterns are basic PostgreSQL patterns, not RegEx: An underscore `(_)` matches any single character; a percent sign
834
-
`(%)` matches any sequence of zero or more characters.
828
+
Patterns are basic PostgreSQL patterns, not RegEx: An underscore `_` matches any single character; a percent sign
829
+
`%` matches any sequence of zero or more characters.
835
830
836
-
Keys can be max 256 bytes long and has to be strings or numbers. Values can be anything, but if their serialized
837
-
representation exceeds 100kB a `short write` error gets raised.
831
+
Keys can be at most 256 bytes long and has to be strings or numbers. Values can be anything, but if their serialized
832
+
representation exceeds 100 kB a `short write` error is raised.
838
833
839
-
You can just pass a `userID`of 0 to make it global (or any other number, but 0 is safe).
834
+
You can just pass a `userID`of 0 to make it global (or any other number, but 0 is safe).
840
835
841
836
There can be 10 database interactions per CC, out of which dbTop/BottomEntries, dbCount, dbGetPattern, and dbDelMultiple
0 commit comments