MCPcopy
hub / github.com/nonebot/nonebot2 / template

Method template

nonebot/internal/adapter/message.py:125–138  ·  view source on GitHub ↗

创建消息模板。 用法和 `str.format` 大致相同,支持以 `Message` 对象作为消息模板并输出消息对象。 并且提供了拓展的格式化控制符, 可以通过该消息类型的 `MessageSegment` 工厂方法创建消息。 参数: format_string: 格式化模板 返回: 消息格式化器

(cls, format_string: str | TM)

Source from the content-addressed store, hash-verified

123
124 @classmethod
125 def template(cls, format_string: str | TM) -> MessageTemplate[Self]:
126 """创建消息模板。
127
128 用法和 `str.format` 大致相同,支持以 `Message` 对象作为消息模板并输出消息对象。
129 并且提供了拓展的格式化控制符,
130 可以通过该消息类型的 `MessageSegment` 工厂方法创建消息。
131
132 参数:
133 format_string: 格式化模板
134
135 返回:
136 消息格式化器
137 """
138 return MessageTemplate(format_string, cls)
139
140 @classmethod
141 @abc.abstractmethod

Callers 4

test_template_messageFunction · 0.80
test_message_injectionFunction · 0.80
test_malformed_templateFunction · 0.80

Calls 1

MessageTemplateClass · 0.85

Tested by 4

test_template_messageFunction · 0.64
test_message_injectionFunction · 0.64
test_malformed_templateFunction · 0.64