索引消息段 参数: value: 消息段或者消息段类型 arg: start 与 end 返回: 索引 index 异常: ValueError: 消息段不存在
(self, value: TMS | str, *args: SupportsIndex)
| 288 | return value in self |
| 289 | |
| 290 | def index(self, value: TMS | str, *args: SupportsIndex) -> int: |
| 291 | """索引消息段 |
| 292 | |
| 293 | 参数: |
| 294 | value: 消息段或者消息段类型 |
| 295 | arg: start 与 end |
| 296 | |
| 297 | 返回: |
| 298 | 索引 index |
| 299 | |
| 300 | 异常: |
| 301 | ValueError: 消息段不存在 |
| 302 | """ |
| 303 | if isinstance(value, str): |
| 304 | first_segment = next((seg for seg in self if seg.type == value), None) |
| 305 | if first_segment is None: |
| 306 | raise ValueError(f"Segment with type {value!r} is not in message") |
| 307 | return super().index(first_segment, *args) |
| 308 | return super().index(value, *args) |
| 309 | |
| 310 | def get(self, type_: str, count: int | None = None) -> Self: |
| 311 | """获取指定类型的消息段 |
no outgoing calls