LogoFuyu Docs

命令注册

命令注册方法

命令注册

  • cmdHandlers: Record<string, CommandDef>:命令路由表,仅在需要响应命令时赋值。单个命令可进一步声明 descriptionhandlerscopepermission。 |

Prop

Type

可以使用我们 TDLib 封装方法或者 TDLib 的原始调用方法来调用 TDLib 方法 文档

Examples.ts
import { Plugin } from "@plugin/BasePlugin.ts";
import type { Client } from "tdl";
import type { updateNewMessage } from "tdlib-types";

export default class LifePlugin extends Plugin {
  name = "插件唯一名称";
  type = "general";
  version = "插件版本号";
  description = "简短描述";

  constructor(client: Client) {
    super(client);

	this.cmdHandlers = {
   // hello为命令
			hello: {
				description: "回复 '你好,世界!'",
				scope:["all"]
				permission:"all"
				showInHelp: true
				handler: async (updateNewMessage, args) => {  
					try {
						await this.client.invoke({
							_: "sendMessage",
							chat_id: updateNewMessage.message.chat_id,
							input_message_content: {
								_: "inputMessageText",
								text: { _: "formattedText", text: "你好,世界!" },
							},
						});
					} catch (e) {
						logger.error("发送消息失败", e);
					}
				},
			},
		};
  }
}

On this page