> For the complete documentation index, see [llms.txt](https://chaoses-ib.gitbook.io/directory-opus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh-1/onscriptcommand.zh.md).

# OnScriptCommand

**OnScriptCommand** 事件是 [内部命令](/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_internal_command.zh.md) 的入口点，该命令由 [脚本加载项](/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-1.md) 添加。事件的实际名称由脚本本身定义，当命令通过 [**ScriptInitData**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/scriptinitdata.zh.md)**.AddCommand** 方法添加时 - **OnScriptCommand** 只是一个占位符名称。

| **方法名称:**  | OnScriptCommand                                                                                                                                                                                                                                                                                                                                  |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **参数类型:**  | [**ScriptCommandData**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/scriptcommanddata.zh.md)                                                                                                                                                                                                                            |
| **返回值类型:** | *bool*                                                                                                                                                                                                                                                                                                                                           |
| **描述:**    | <p>当脚本加载项使用 <strong>ScriptInitData.AddCommand</strong> 添加一个新的内部命令时，它会使用 <strong>ScriptCommand.method</strong> 属性指定其入口点的名称。当内部命令运行时，Opus 会在你的脚本中调用该方法。<br><strong>ScriptCommandData.func</strong> 属性提供有关命令环境的信息（包括任何解析后的参数），<strong>cmdline</strong> 属性提供调用你的命令的原始命令行。<br>如果此事件返回 <strong>True</strong>，则该函数将被中止 - 如果你遇到错误并且用户选择中止操作，你可能会这样做。</p> |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh-1/onscriptcommand.zh.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
