Update main.py

This commit is contained in:
Soulter 2025-04-12 18:34:01 +08:00 committed by GitHub
parent b25bc0640c
commit 46532ab3c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,11 +6,14 @@ from astrbot.api import logger
class MyPlugin(Star):
def __init__(self, context: Context):
super().__init__(context)
async def initialize(self):
"""可选择实现异步的插件初始化方法,当实例化该插件类之后会自动调用该方法。"""
# 注册指令的装饰器。指令名为 helloworld。注册成功后发送 `/helloworld` 就会触发这个指令,并回复 `你好, {user_name}!`
@filter.command("helloworld")
async def helloworld(self, event: AstrMessageEvent):
'''这是一个 hello world 指令''' # 这是 handler 的描述,将会被解析方便用户了解插件内容。建议填写。
"""这是一个 hello world 指令""" # 这是 handler 的描述,将会被解析方便用户了解插件内容。建议填写。
user_name = event.get_sender_name()
message_str = event.message_str # 用户发的纯文本消息字符串
message_chain = event.get_messages() # 用户所发的消息的消息链 # from astrbot.api.message_components import *
@ -18,4 +21,4 @@ class MyPlugin(Star):
yield event.plain_result(f"Hello, {user_name}, 你发了 {message_str}!") # 发送一条纯文本消息
async def terminate(self):
'''可选择实现 terminate 函数,当插件被卸载/停用时会调用。'''
"""可选择实现异步的插件销毁方法,当插件被卸载/停用时会调用。"""