Skip to content

Commit 32f6e40

Browse files
committed
feature: Add documentation for $aiAgent and $listVar functions
1 parent 7316071 commit 32f6e40

4 files changed

Lines changed: 138 additions & 0 deletions

File tree

book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
8585

8686
# Premium functions - Don't touch!
8787
"/bdscript/ai.html" = "../premium/ai.html"
88+
"/bdscript/aiAgent.html" = "../premium/aiAgent.html"
8889
"/bdscript/aiDecide.html" = "../premium/aiDecide.html"
8990
"/bdscript/aiDecideWithCtx.html" = "../premium/aiDecideWithCtx.html"
9091
"/bdscript/aiQuota.html" = "../premium/aiQuota.html"

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@
430430
- [$getUserVar](./bdscript/getUserVar.md)
431431
- [$getVar](./bdscript/getVar.md)
432432
- [$globalUserLeaderboard](./bdscript/globalUserLeaderboard.md)
433+
- [$listVar](./bdscript/listVar.md)
433434
- [$resetChannelVar](./bdscript/resetChannelVar.md)
434435
- [$resetServerVar](./bdscript/resetServerVar.md)
435436
- [$resetUserVar](./bdscript/resetUserVar.md)
@@ -531,6 +532,7 @@
531532
- [$aiDecide](./premium/aiDecide.md)
532533
- [$aiWithCtx](./premium/aiWithCtx.md)
533534
- [$aiDecideWithCtx](./premium/aiDecideWithCtx.md)
535+
- [$aiAgent](./premium/aiAgent.md)
534536
- [$aiQuota](./premium/aiQuota.md)
535537
- [$awaitReactions](./premium/awaitReactions.md)
536538
- [$customImage](./premium/customImage.md)

src/bdscript/listVar.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# $listVar
2+
Returns a list of all variable names defined for this bot.
3+
4+
## Syntax
5+
```
6+
$listVar[(Separator)]
7+
```
8+
9+
### Parameters
10+
- `Separator` `(Type: String || Flag: Optional)`: The string used to separate variable names. Defaults to `, `.
11+
12+
## Example
13+
```
14+
$nomention
15+
$listVar[, ]
16+
```
17+
18+
``` discord yaml
19+
- user_id: 803569638084313098
20+
username: RainbowKey
21+
color: "#E67E22"
22+
content: |
23+
!example
24+
- username: BDFD Support
25+
user_id: 1009018156494368798
26+
color: "#378afa"
27+
bot: true
28+
verified: true
29+
content: |
30+
Money, Level, XP
31+
```
32+
33+
```admonish info title="Read more"
34+
For more information, read the [Variables Guide](../guides/introduction/variables.md).
35+
```

src/premium/aiAgent.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# $aiAgent
2+
<div class="functionTags">
3+
<span id="PremiumTag">Premium</span>
4+
</div>
5+
6+
Prompts AI with Discord message context, an optional system prompt, and a list of BDScript functions it can call as tools. The AI may invoke those functions iteratively (up to 10 times) before producing a final response.
7+
8+
## Syntax
9+
```
10+
$aiAgent[Prompt;(System prompt;Functions;Response token limit)]
11+
```
12+
13+
```admonish tip title="AI Quota"
14+
[4 characters in the AI answer](./ai.md) = [1 token](./aiQuota.md)
15+
```
16+
17+
### Parameters
18+
- `Prompt` `(Type: String || Flag: Required)`: The prompt sent to the AI, for example: "What is the user's score?".
19+
- `System prompt` `(Type: String || Flag: Optional)`: Additional system prompt appended after the message context.
20+
- `Functions` `(Type: String || Flag: Optional)`: Comma-separated list of BDScript function names the AI may call as tools, for example: `getVar,setVar,title`.
21+
- `Response token limit` `(Type: Integer || Flag: Optional)`: Limit the response length per iteration. Approximately 4 characters equals 1 token.
22+
23+
### Context provided to AI
24+
The following information from the triggering Discord message is automatically included:
25+
26+
| Field | Description |
27+
|-------------------|------------------------------------------|
28+
| Author | Username and user ID |
29+
| Author nickname | Server nickname, if set |
30+
| Channel | Channel name |
31+
| Server | Server name |
32+
| Timestamp | Message sent time |
33+
| Edited at | Edit time, if the message was edited |
34+
| Mentions everyone | Whether `@everyone` was used |
35+
| Mentions | Usernames and IDs of mentioned users |
36+
| Attachments | Filenames of attached files |
37+
| Reactions | Emoji name and reaction count |
38+
39+
### How it works
40+
The AI can call any of the listed BDScript functions as tools. After each tool call the result is fed back to the AI, which may call another tool or return its final answer. This loop runs for at most **10 iterations**. If the limit is reached, the last assistant message is returned.
41+
42+
```admonish warning title="Security warning"
43+
Be cautious when granting access to powerful or sensitive functions (e.g. `setVar`, `setUserVar`, `ban`). Any user who can trigger the command can craft a prompt that instructs the AI to call those functions on their behalf — a risk known as **prompt injection**. Consider restricting such commands to bot owners or trusted roles.
44+
```
45+
46+
## Example
47+
```
48+
$nomention
49+
$aiAgent[$message;Answer the user's question using their stored score if needed.;listVar,getUserVar]
50+
```
51+
52+
``` discord yaml
53+
- user_id: 803569638084313098
54+
username: RainbowKey
55+
color: "#E67E22"
56+
content: |
57+
!example What is my score?
58+
- user_id: 1009018156494368798
59+
username: BDFD Support
60+
color: "#378afa"
61+
bot: true
62+
verified: true
63+
content: |
64+
Your current score is 42!
65+
```
66+
\
67+
68+
## Example with embed
69+
```
70+
$nomention
71+
$aiAgent[$message;;listVar,getUserVar,setUserVar,title,description,color]
72+
```
73+
74+
``` discord yaml
75+
- user_id: 803569638084313098
76+
username: RainbowKey
77+
color: "#E67E22"
78+
content: |
79+
!example Can you send an embed with title "test" and a description showing the value of my coins variable and pink color?
80+
- user_id: 1009018156494368798
81+
username: BDFD Support
82+
color: "#378afa"
83+
bot: true
84+
verified: true
85+
content: |
86+
The embed has been created with the title "test", a description of your coins value (123), and is colored pink. If you need anything else, let me know!
87+
embed:
88+
title: test
89+
description: "Your coins value: 123"
90+
color: "#FF69B4"
91+
```
92+
\
93+
94+
```admonish tip
95+
Use [`$aiWithCtx[]`](./aiWithCtx.md) if you don't need the AI to call any BDScript functions as tools.
96+
```
97+
98+
```admonish tip
99+
Use [`$aiQuota`](./aiQuota.md) to check how many tokens you have left.
100+
```

0 commit comments

Comments
 (0)