Kaynağa Gözat

feat(插件): 在构造函数中注册qqBot事件以测试插件加载

在测试插件的构造函数中添加了qqBot的事件监听,当收到消息内容为“自测”时,回复“插件加载事件测试”以验证插件加载是否成功
枫林 3 ay önce
ebeveyn
işleme
9d51133600
1 değiştirilmiş dosya ile 16 ekleme ve 0 silme
  1. 16 0
      src/plugins/test.ts

+ 16 - 0
src/plugins/test.ts

@@ -19,6 +19,22 @@ import { ParamType } from '../interface/plugin.js';
     }
 })
 export class test {
+    constructor() {
+        //构造函数内可以再次注册qqBot的事件
+        qqBot.on('message', async (event) => {
+            event.message.forEach(async (message) => {
+                if (message.type === 'text') {
+                    if (message.data.text === '自测') {
+                        await event.quick_action([{
+                            type: 'text',
+                            data: { text: `插件加载事件测试` }
+                        }]);
+                    }
+                }
+            })
+        })
+        botlogger.info("测试插件加载成功")
+    }
     @runcod(["param"], "参数实例")//命令装饰器,用于注册命令
     async param(
         @param("参数1", ParamType.String) param1: string,//参数装饰器,用于解析参数