17TheWord / nonebot-adapter-minecraft

NoneBot2的Minecraft Server适配器
MIT License
23 stars 2 forks source link

无法与mc服务端建立连接 #34

Closed YuYue-Amatsuki closed 4 months ago

YuYue-Amatsuki commented 4 months ago

当服务端尝试与nonebot建立连接时,nonebot提示403

05-26 22:48:10 [INFO] uvicorn | ('127.0.0.1', 51824) - "WebSocket /minecraft/ws" 403
05-26 22:48:10 [INFO] websockets | connection failed (403 Forbidden)
05-26 22:48:10 [INFO] websockets | connection closed

mc服务端日志如下

mcqq client reconnect
[22:48:05 INFO]: 即将重新连接未处于开启状态的 Websocket Client...
[22:48:05 INFO]: 正在尝试重连至:ws://127.0.0.1:11451/minecraft/ws 的 WebSocket 服务器...
[22:48:05 INFO]: 重连完成
[22:48:10 INFO]: [MC_QQ] 连接至:ws://127.0.0.1:11451/minecraft/ws 的 WebSocket 连接已断开,尝试第 4 次重连...

mc服务端的配置如下

# WebSocket Server配置项
websocket_server:
  enable: true
  host: "127.0.0.1"
  port: 8089

# 请在冒号后填写 WebSocket 地址。
# 默认:ws://127.0.0.1:8080/minecraft/ws
websocket_client:
  enable: true
  url_list:
    - "ws://127.0.0.1:11451/minecraft/ws"

nonebot的配置如下

HOST=127.0.0.1  # 配置 NoneBot2 监听的 IP/主机名
PORT=11451  # 配置 NoneBot2 监听的端口
SUPERUSERS=["245*****73"]  # 配置 NoneBot 超级用户
NICKNAME=["awesome", "bot"]  # 配置机器人的昵称
COMMAND_START=["/", "","#"]  # 配置命令起始字符
COMMAND_SEP=["."]  # 配置命令分割字符
DRIVER=~fastapi+~httpx+~websockets
mc_qq__say_way = ":"
mc_qq__server_dict = '{
    "SkyLine Server": {
        "group_list": [
            {
                "group_id": "97*****92",
                "adapter": "onebot",
                "bot_id": "25*****89"
            }
        ],
        "guild_list": [
            {
                "guild_id": "",
                "channel_id": "",
                "adapter": "qq",
                "bot_id": ""
            }
        ],
        "rcon_msg": false,
        "rcon_cmd": true
    }
}'
minecraft_ws_urls = '{
    "SkyLine Server": ["ws://127.0.0.1:8089"]
}'
minecraft_server_rcon = '{
    "SkyLine Server": {
        "enable_rcon": true,
        "rcon_port": 25575,
        "rcon_password": ""
    }
}'
mc_qq__rcon_click_action_enable = true
mc_qq__rcon_hover_event_enable = true
mc_qq__rcon_text_component_status = 2
YuYue-Amatsuki commented 4 months ago

已确认minecraft适配器已经安装到nonebot框架中 image

17TheWord commented 4 months ago

机器人目录是否有bot.py? 将nb日志等级改完debug查看启动器是否被加载,LOG_LEVEL=DEBUG

另外正向和反向websocket只需要配置一个连接到mc服务器即可,不用配置两次。

YuYue-Amatsuki commented 4 months ago

机器人目录是否有bot.py? 将nb日志等级改完debug查看启动器是否被加载,LOG_LEVEL=DEBUG

另外正向和反向websocket只需要配置一个连接到mc服务器即可,不用配置两次。

机器人目录下有bot.py,但使用nb run --reload启动bot,mc服务端仍然无法连接到nonebot

启动日志如下

╭─    ~/nonebot/yuyue-nonebot                                            ✔  6s   system   yuyue@yuyue-ubuntu  12:33:00  ─╮
╰─ nb run --reload      
启动重载监视,当前进程 [2192703].
05-27 12:34:21 [SUCCESS] nonebot | NoneBot is initializing...
05-27 12:34:21 [INFO] nonebot | Current Env: prod
05-27 12:34:21 [DEBUG] nonebot | Loaded Config: {'driver': '~fastapi+~httpx+~websockets', 'host': IPv4Address('127.0.0.1'), 'port': 11451, 'log_level': 'DEBUG', 'api_timeout': 30.0, 'superusers': {'245*****73'}, 'nickname': {'awesome', 'bot'}, 'command_start': {'', '#', '/'}, 'command_sep': {'.'}, 'session_expire_timeout': datetime.timedelta(seconds=120), 'environment': 'prod', 'ps_ignore_no_io_disk': 'True', 'mc_qq': {'say_way': ':', 'server_dict': {'SkyLine Server': {'group_list': [{'group_id': '65*****47', 'adapter': 'onebot', 'bot_id': '25*****89'}], 'rcon_msg': False, 'rcon_cmd': True}}, 'rcon_click_action_enable': True, 'rcon_hover_event_enable': True, 'rcon_text_component_status': 2}, 'minecraft_server_rcon': {'SkyLine Server': {'enable_rcon': True, 'rcon_port': 25575, 'rcon_password': ''}}, 'ps_test_sites': [{'name': '百度', 'url': 'https://baidu.com'}], 'ps_ignore_bad_parts': 'True', 'custom_config': 'common config', 'ps_proc_len': 5, 'reboot_grace_time_limit': 20, 'ps_ignore_0b_net': 'False', 'ps_ignore_parts': ['/snap*', '/run*', '/loop*'], 'is_random_robbed': 'True', 'ps_proc_sort_by': 'cpu', 'is_random_give,is_random_eat': 'True', 'global_database': 'True', 'ps_ignore_nets': ['docker*', 'veth*'], 'mcstat_show_addr': 'True', 'cd_buy,cd_eat,cd_rob,cd_give,cd_bet': 60, 'reboot_load_command': 'True', 'ps_custom_bg': ['https://t.lizi.moe/mp'], 'ps_font': '/home/yuyue/nonebot/yuyue-nonebot/data/JBL-Medium.ttf', 'ps_proc_cpu_max_100p': 'True', 'mcstat_shortcuts': [{'regex': '^查服je$', 'host': 'bug******.top:25565', 'type': 'je'}, {'regex': '^查服be$', 'host': 'bug******.top:19132', 'type': 'be'}, {'regex': '^查服sl$', 'host': 'bug******.top:20050', 'type': 'je'}, {'regex': '^查服sb$', 'host': 'bug******.top:19000', 'type': 'be'}, {'regex': '^查服slbe$', 'host': 'bug******.top:20060', 'type': 'be'}], 'is_random_given': 'True', 'mcstat_font': 'Unifont'}
05-27 12:34:21 [DEBUG] nonebot | Succeeded to load adapter "OneBot V11"
05-27 12:34:21 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
05-27 12:34:21 [SUCCESS] nonebot | Succeeded to load plugin "longtu" from "plugins.longtu"
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_alconna:uniseg" from "nonebot_plugin_alconna.uniseg"
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_alconna"
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_picmcstat"
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_userinfo"
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_htmlrender"
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector nonebot_run_time
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector system_run_time
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector nonebot_version
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector ps_version
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector time
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector python_version
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector system_name
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector bots
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector cpu_brand
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector cpu_count_logical
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector cpu_count
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector cpu_percent
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector cpu_freq
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector memory_stat
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector swap_stat
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector disk_usage
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector disk_io
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector process_status
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector network_io
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered collector network_connection
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered global jinja filter `format_cpu_freq`
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered global jinja filter `percent_to_color`
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered global jinja filter `auto_convert_unit`
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Registered global jinja filter `br`
05-27 12:34:22 [DEBUG] nonebot_plugin_picstatus | Loaded template default TemplateInfo(collectors={'cpu_brand', 'ps_version', 'swap_stat', 'network_connection', 'system_name', 'disk_usage', 'process_status', 'system_run_time', 'cpu_count', 'nonebot_run_time', 'nonebot_version', 'cpu_freq', 'time', 'disk_io', 'cpu_percent', 'bots', 'network_io', 'python_version', 'memory_stat', 'cpu_count_logical'}, config=TemplateConfig(ps_default_components=['header', 'cpu_mem', 'disk', 'network', 'process', 'footer'], ps_default_additional_css=[], ps_default_additional_script=[]), renderer=<function render at 0x7ee24f7eecb0>)
05-27 12:34:22 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_picstatus"
05-27 12:34:23 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_ottohzys"
05-27 12:34:23 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_gsabyss"
05-27 12:34:23 [WARNING] nonebot_plugin_directlinker | [直链提取] 未发现配置项 `linker_group` , 采用默认值: []
05-27 12:34:23 [WARNING] nonebot_plugin_directlinker | [直链提取] 未发现配置项 `linker_command` , 采用默认值: "link"
05-27 12:34:23 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_directlinker"
05-27 12:34:24 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_guild_patch"
05-27 12:34:24 [DEBUG] nonebot | Minecraft | Model for key "/message" <class 'nonebot.adapters.minecraft.event.base.BaseChatEvent'> is overridden by <class 'nonebot.adapters.minecraft.event.base.BaseDeathEvent'>
05-27 12:34:24 [DEBUG] nonebot | Minecraft | Model for key "/notice" <class 'nonebot.adapters.minecraft.event.base.BaseJoinEvent'> is overridden by <class 'nonebot.adapters.minecraft.event.base.BaseQuitEvent'>
05-27 12:34:24 [DEBUG] nonebot | Minecraft | Model for key "/message/ServerMessageEvent" <class 'nonebot.adapters.minecraft.event.fabric.ServerMessageEvent'> is overridden by <class 'nonebot.adapters.minecraft.event.fabric.ServerMessageEvent'>
05-27 12:34:24 [DEBUG] nonebot | Minecraft | Model for key "/message" <class 'nonebot.adapters.minecraft.event.base.BaseDeathEvent'> is overridden by <class 'nonebot.adapters.minecraft.event.base.MessageEvent'>
05-27 12:34:24 [DEBUG] nonebot | Minecraft | Model for key "/notice" <class 'nonebot.adapters.minecraft.event.base.BaseQuitEvent'> is overridden by <class 'nonebot.adapters.minecraft.event.base.NoticeEvent'>
05-27 12:34:24 [DEBUG] nonebot | Minecraft | Model for key "/message/PlayerDeathEvent" <class 'nonebot.adapters.minecraft.event.forge.PlayerDeathEvent'> is overridden by <class 'nonebot.adapters.minecraft.event.spigot.PlayerDeathEvent'>
05-27 12:34:24 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_mcqq"
05-27 12:34:24 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_bread_shop"
05-27 12:34:24 [WARNING] __main__ | Always use `nb run` to start the bot instead of manually running!
05-27 12:34:24 [SUCCESS] nonebot | Running NoneBot...
05-27 12:34:24 [DEBUG] nonebot | Loaded adapters: OneBot V11
05-27 12:34:24 [INFO] uvicorn | Started server process [2192703]
05-27 12:34:24 [INFO] uvicorn | Waiting for application startup.
05-27 12:34:24 [INFO] nonebot_plugin_apscheduler | Scheduler Started
05-27 12:34:24 [INFO] nonebot_plugin_htmlrender | 使用 chromium 启动
05-27 12:34:24 [INFO] nonebot_plugin_htmlrender | Browser Started.
05-27 12:34:26 [INFO] nonebot_plugin_gsabyss | HHW 深渊数据已缓存,跳过更新
05-27 12:34:26 [INFO] uvicorn | Application startup complete.
05-27 12:34:26 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:11451 (Press CTRL+C to quit)
05-27 12:34:30 [INFO] uvicorn | ('127.0.0.1', 52343) - "WebSocket /onebot/v11/ws" [accepted]
05-27 12:34:30 [INFO] nonebot | OneBot V11 | Bot 2*****689 connected
05-27 12:34:30 [INFO] websockets | connection open
05-27 12:34:30 [DEBUG] nonebot | Running PreProcessors...
05-27 12:34:30 [DEBUG] nonebot_plugin_picstatus | Event has no context!
05-27 12:35:09 [INFO] uvicorn | ('127.0.0.1', 59544) - "WebSocket /minecraft/ws" 403
05-27 12:35:09 [INFO] websockets | connection failed (403 Forbidden)
05-27 12:35:09 [INFO] websockets | connection closed
17TheWord commented 4 months ago

你的Nonebot并没有启动Minecraft适配器,只有Onebot V11

05-27 12:34:21 [DEBUG] nonebot | Succeeded to load adapter "OneBot V11"
YuYue-Amatsuki commented 4 months ago

你的Nonebot并没有启动Minecraft适配器,只有Onebot V11

05-27 12:34:21 [DEBUG] nonebot | Succeeded to load adapter "OneBot V11"

请问该如何修改配置文件来启动适配器?

17TheWord commented 4 months ago

可以前往 mcqq wiki 查看这些问题的帮助

如果你用的是 旧版/成品机器人,这里也有 bot.py 手动注册适配器的方式

from nonebot import get_driver
from nonebot.adapters.minecraft import Adapter as MinecraftAdapter

driver = get_driver()
driver.register_adapter(MinecraftAdapter)