> 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/oninit.zh.md).

# OnInit

**OnInit** 事件在每个 [脚本加载项](/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-1.md) 初始化时被调用一次。该事件会在程序启动时被调用，如果在 Opus 运行时添加或编辑脚本，也会被调用。实现 **OnInit** 事件是可选的，但强烈推荐，因为它允许您提供一个名称、描述和其它信息，以便在配置中向用户显示。它还为脚本提供了一种方式来 [添加内部命令](/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-6/adding_a_new_column.zh.md)（尽管 [**OnAddCommands**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh-1/onaddcommands.zh.md) 和 [**OnAddColumns**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh-1/onaddcolumns.zh.md) 方法提供了更好的方法来执行此操作）。

| **方法名称：** | OnInit                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **参数类型：** | [**ScriptInitData**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/scriptinitdata.zh.md)                                                                                                                                                                                                                                                                                                                                                          |
| **返回类型：** | *bool*                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| **描述：**   | 当 Opus 启动，或当脚本加载项被添加或编辑时，它的 **OnInit** 方法会被调用。这为脚本提供了一个机会，通过设置 **ScriptInitData** 对象的各种属性来告诉 Opus 有关自身的信息。**AddCommand** 方法也可以从该事件中使用来 [添加内部命令](/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_internal_command.zh.md) 到 Opus 命令集中，AddColumn 方法可以用来添加 [列](/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_column.zh.md)。 如果您从该方法返回 **True**，则脚本将被禁用，直到下次调用 **OnInit**（通常是在下次运行 Opus 时）。例如，如果 Windows 的版本不适合您的脚本，您可能需要这样做。 |


---

# 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/oninit.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.
