|
| 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