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.
@@ -161,7 +155,7 @@ Similarly, provided a channel `$channel`, `$channel.Name` gives the name of the
161
155
| .Guild.OwnerID | Outputs the ID of the owner. |
162
156
| .Guild.PreferredLocale | The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US" |
163
157
| .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). |
164
-
| .Guild.Stickers | A slice of all [sticker objects] in the guild. |
158
+
| .Guild.Stickers | A slice of all [sticker objects] in the guild. |
165
159
| .Guild.Splash | Outputs the [splash hash](https://discordapp.com/developers/docs/reference#image-formatting) ID of the guild's splash. |
166
160
| .Guild.SystemChannelID | The ID of the channel where guild notices such as welcome messages and boost events are posted. |
167
161
| .Guild.Threads | Returns all active threads in the guild as a slice of type _\[]dstate.ChannelState_. |
@@ -252,7 +246,7 @@ Interaction functions are covered [here](/docs/reference/templates/functions#int
252
246
| .Message.ChannelID | Channel ID this message is in. |
253
247
| .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 )`|
254
248
| .Message.Content | Text content of this message. |
255
-
| .Message.ContentWithMentionsReplaced | Replaces all <@ID> mentions with the username of the mention. |
249
+
| .Message.ContentWithMentionsReplaced | Replaces all `<@ID>` mentions with the username of the mention. |
256
250
| .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._|
257
251
| .Message.Embeds | Embeds of this message (_slice_ of embed objects). |
258
252
| .Message.Flags | Message flags, represented as a bit set. |
@@ -312,7 +306,7 @@ This is available and part of the dot when reaction trigger type is used.
312
306
| .ReactionAdded | Returns a boolean type _bool_ true/false indicating whether reaction was added or removed. |
313
307
| .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. |
314
308
315
-
[Reaction object in Discord documentation](https://discordapp.com/developers/docs/resources/message#reaction-object).\
309
+
[Reaction object in Discord documentation](https://discordapp.com/developers/docs/resources/message#reaction-object).
316
310
[Emoji object in Discord documentation.](https://discord.com/developers/docs/resources/emoji)
317
311
318
312
### User
@@ -379,7 +373,7 @@ to `eq`.
379
373
380
374
Comparison operators always require the same type: i.e comparing `1.23` and `1` would throw **`incompatible types for
381
375
comparison`** error as they are not the same type (one is float, the other int). To fix this, you should convert both to
382
-
the same type -> for example, `toFloat 1`.
376
+
the same type, for example, `toFloat 1`.
383
377
384
378
{{< /callout >}}
385
379
@@ -422,17 +416,18 @@ if one wishes to skip all remaining iterations, the `{{break}}` action may be us
422
416
423
417
{{< /callout >}}
424
418
425
-
Affected dot inside `range` is important because methods mentioned above in this documentation:`.Server.ID`,
426
-
`.Message.Content` etc are all already using the dot on the pipeline and if they are not carried over to the `range`
427
-
control structure directly, these fields do not exists and template will error out. Getting those values inside `range`
428
-
and also `with` action would need `$.User.ID` for example.\
429
-
\
419
+
Affected dot inside `range` is important because methods mentioned above in this documentation like `.Server.ID`,
420
+
are all already using the dot on the pipeline and if they are not carried over to the `range` control structure
421
+
directly, these fields do not necessarily exists and template will error out. Getting those values inside `range`
422
+
and also `with` action would need to use the global syntax (e.g. `$.Server.ID`).
423
+
430
424
`range` on slices/arrays provides both the index and element for each entry; `range` on map iterates over key/element
431
425
pairs. If a `range` action initializes a variable, that variable is set to the successive elements of the iteration.
432
426
`range` can also declare two variables, separated by a comma and set by index and element or key and element pair. In
433
-
case of only one variable, it is assigned the element.\
434
-
\
435
-
Like `if`, `range`is concluded with`{{end}}`action and declared variable scope inside `range` extends to that point.\
427
+
case of only one variable, it is assigned the element.
428
+
429
+
Like `if`, `range` is concluded with the `{{end}}` action and declared variable scope inside `range` extends to that
430
+
point.
436
431
437
432
```yag
438
433
{{/* range over an integer */}}
@@ -464,7 +459,7 @@ Hello!
464
459
```
465
460
466
461
This program iterates ten *thousand* times, adding a newline and a tab character on every iteration to the output---we
467
-
can fix this error by telling the bot to throw away (or "strip") whitespace characters by using the trim indicator `-`:
462
+
can fix this error by telling the bot to throw away (or "strip") whitespace characters by using the trim indicator `-`.
468
463
469
464
```yag
470
465
{{ range 10000 }}
@@ -490,10 +485,10 @@ Similar to an `if` action with an associated `else` branch, the `try`-`catch` co
490
485
`try` branch and the `catch` branch. First, the code in the `try` branch is ran, and if an error is raised by a function
491
486
during execution, the `catch` branch is executed instead with the context (`.`) set to the offending error.
492
487
493
-
To check for a specific error, one can compare the result of the `Error` method with a predetermined message. (For
488
+
To check for a specific error, one can compare the result of the `Error` method with a predetermined message. For
494
489
context, all errors have a method `Error` which is specified to return a message describing the reason that the error
495
-
was thrown.) For example, the following example has different behavior depending on whether "Reaction blocked" is in the
496
-
message of the error caught.
490
+
was thrown. The following example has different behavior depending on whether "Reaction blocked" is in the message of
491
+
the error caught.
497
492
498
493
```yag
499
494
{{ try }}
@@ -543,8 +538,8 @@ appropriate effect, like in a `range` action.
543
538
544
539
`with` lets you assign and carry pipeline value with its type as a dot (`.`) inside that control structure, it's like a
545
540
shorthand. If the value of the pipeline is empty, dot is unaffected and when an `else` or `else if` action is used,
546
-
execution moves on to those branches instead, similar to the `if` action.\
547
-
\
541
+
execution moves on to those branches instead, similar to the `if` action.
542
+
548
543
Affected dot inside `with` is important because methods mentioned above in this documentation:`.Server.ID`,
549
544
`.Message.Content` etc are all already using the dot on the pipeline and if they are not carried over to the `with`
550
545
control structure directly, these fields do not exists and template will error out. Getting those values inside `with`
@@ -593,7 +588,7 @@ To define an associated template, use the `define` action. It has the following
593
588
594
589
{{< callout context="danger" title="Danger: Associated Templates at Top Level" icon="outline/alert-octagon" >}}
595
590
596
-
**Warning:**Template definitions must be at the top level of the custom command program; in other words, they cannot be
591
+
Template definitions must be at the top level of the custom command program; in other words, they cannot be
597
592
nested in other actions (for example, an if action.) That is, the following custom command is invalid:
598
593
599
594
```yag
@@ -653,7 +648,7 @@ will result in execution of the custom command being stopped at the point the `r
653
648
654
649
### Execution
655
650
656
-
To execute a custom command, one of three methods may be used: `template`, `block`, or `execTemplate`.
651
+
To execute an associated template, one of three methods may be used: `template`, `block`, or `execTemplate`.
657
652
658
653
#### Template action
659
654
@@ -684,7 +679,7 @@ Below is an example of the `template` action in action:
684
679
{{ template "sayHi" "YAG" }} {{/* hi there, YAG */}}
685
680
```
686
681
687
-
Trim markers: `{{- ... -}}`were used in above example because whitespace is considered as part of output for associated
682
+
Trim markers: `{{- ... -}}`were used in above example because whitespace is considered as part of output for associated
688
683
template definitions (and actions in general).
689
684
690
685
#### Block action
@@ -853,13 +848,13 @@ You can have max 50 \* user_count (or 500 \* user_count for premium) values in t
853
848
new write functions will fail, this value is also cached, so it won't be detected immediately when you go above nor
854
849
immediately when you're under again.
855
850
856
-
Patterns are basic PostgreSQL patterns, not RegEx: An underscore `(_)` matches any single character; a percent sign
857
-
`(%)` matches any sequence of zero or more characters.
851
+
Patterns are basic PostgreSQL patterns, not RegEx: An underscore `_` matches any single character; a percent sign
852
+
`%` matches any sequence of zero or more characters.
858
853
859
-
Keys can be max 256 bytes long and has to be strings or numbers. Values can be anything, but if their serialized
860
-
representation exceeds 100kB a `short write` error gets raised.
854
+
Keys can be at most 256 bytes long and has to be strings or numbers. Values can be anything, but if their serialized
855
+
representation exceeds 100 kB a `short write` error is raised.
861
856
862
-
You can just pass a `userID`of 0 to make it global (or any other number, but 0 is safe).
857
+
You can just pass a `userID`of 0 to make it global (or any other number, but 0 is safe).
863
858
864
859
There can be 10 database interactions per CC, out of which dbTop/BottomEntries, dbCount, dbGetPattern, and dbDelMultiple
0 commit comments