nonebot / nonebot2

跨平台 Python 异步聊天机器人框架 / Asynchronous multi-platform chatbot framework written in Python
https://nonebot.dev
MIT License
5.86k stars 554 forks source link

创建插件和注册事件之后测试一直没反应 #315

Closed youlingforever0328 closed 3 years ago

youlingforever0328 commented 3 years ago

**windows下,创建插件和注册事件之后测试一直没反应 Checking for matchers in priority 1...

yanyongyu commented 3 years ago

请给出你的日志截图和代码,不按格式来的我怎么回答你啊(

youlingforever0328 commented 3 years ago

自定义插件代码: esp32cam.py:

from nonebot import on_command from nonebot.rule import to_me from nonebot.typing import T_State from nonebot.adapters import Bot, Event

weather = on_command("天气", rule=to_me(), priority=1)

@weather.handle() async def handle_first_receive(bot: Bot, event: Event, state: T_State):     args = str(event.get_message()).strip()  # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海     print(f"==={args}===")     if args:         state["city"] = args  # 如果用户发送了参数则直接赋值

@weather.got("city", prompt="你想查询哪个城市的天气呢?") async def handle_city(bot: Bot, state: T_State):     city = state["city"]     if city not in ["上海", "北京"]:         await weather.reject("你想查询的城市暂不支持,请重新输入!")     # weather = await get_weather_from_xxx(city)     city_weather = "晴天"     # await bot.send(city_weather)     await weather.finish(city_weather)

bot.py:

!/usr/bin/env python3

-- coding: utf-8 --

import nonebot from nonebot.adapters.cqhttp import Bot as CQHTTPBot

Custom your logger

 

from nonebot.log import logger, default_format

logger.add("error.log",

            rotation="00:00",

            diagnose=False,

            level="ERROR",

            format=default_format)

You can pass some keyword args config to init function

nonebot.init()

driver = nonebot.get_driver() driver.register_adapter("cqhttp", CQHTTPBot)

nonebot.load_builtin_plugins() nonebot.load_from_toml("pyproject.toml")   nonebot.load_plugins("src/plugins") # 自定义的插件esp32cam在src/plugins下

app = nonebot.get_asgi()

Modify some config / config depends on loaded configs

 

config = driver.config

do something...

if name == "main":     nonebot.logger.warning("Always use nb run to start the bot instead of manually running!")     nonebot.run(app="__mp_main__:app")

------------------ 原始邮件 ------------------ 发件人: "nonebot/nonebot2" @.>; 发送时间: 2021年4月6日(星期二) 晚上6:41 @.>; @.**@.>; 主题: Re: [nonebot/nonebot2] windows下,创建插件和注册事件之后测试一直没反应 Checking for matchers in priority 1... (#315)

请给出你的日志截图和代码,不按格式来的我怎么回答你啊(

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

yanyongyu commented 3 years ago

能否截图或者使用markdown代码块格式发送,我这看到的全是乱码,还有提供你的完整日志

youlingforever0328 commented 3 years ago

------------------ 原始邮件 ------------------ 发件人: "nonebot/nonebot2" @.>; 发送时间: 2021年4月6日(星期二) 晚上7:00 @.>; @.**@.>; 主题: Re: [nonebot/nonebot2] windows下,创建插件和注册事件之后测试一直没反应 Checking for matchers in priority 1... (#315)

能否截图或者使用markdown代码块格式发送,我这看到的全是乱码

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

yanyongyu commented 3 years ago

请你使用github网页版或官方客户端进行回复,你这邮件回复全是乱码

youlingforever0328 commented 3 years ago

自定义插件代码 esp32cam.py

image

bot.py

image

运行结果 发送“天气”,一直在Checking for matchers in priority 1...

image

yanyongyu commented 3 years ago

你的配置使用的是 command_start=["/"] 请你使用 /天气 触发命令

youlingforever0328 commented 3 years ago

好的,感谢