FengLiuFeseliud / pycqBot

go-cqhttp python 框架,可以用于快速塔建 bot
https://fengliufeseliud.github.io/pycqBot/
GNU Affero General Public License v3.0
128 stars 29 forks source link

创建指令代码运行失败 #18

Closed bm567 closed 1 year ago

bm567 commented 1 year ago

环境: 芯片 Apple M2 macos 13.3.1 (22E261) python 3.11.2 gocqhttp 1.0.1 pycqBot 0.5.1.1 运行代码:

from pycqBot import cqHttpApi, cqBot, cqLog
from pycqBot.data import *

cqLog()

def test(command_data, message: Message):
    message.reply("你好!")

bot = cqHttpApi().create_bot()
# 创建指令 "#test"
bot.command(test, "test")

bot.start()

报错代码:

#################################################################
██████╗ ██╗   ██╗ ██████╗ ██████╗ ██████╗  ██████╗ ████████╗
██╔══██╗╚██╗ ██╔╝██╔════╝██╔═══██╗██╔══██╗██╔═══██╗╚══██╔══╝
██████╔╝ ╚████╔╝ ██║     ██║   ██║██████╔╝██║   ██║   ██║   
██╔═══╝   ╚██╔╝  ██║     ██║▄▄ ██║██╔══██╗██║   ██║   ██║   
██║        ██║   ╚██████╗╚██████╔╝██████╔╝╚██████╔╝   ██║   
╚═╝        ╚═╝    ╚═════╝ ╚══▀▀═╝ ╚═════╝  ╚═════╝    ╚═╝   
                                            v0.5.1.1  BY FengLiu
#################################################################

[2023-04-26 17:25:00,753][MainThread/DEBUG] PyCqBot: Using selector: KqueueSelector
Exception in thread go-cqhttp:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/kibo/PycharmProjects/wfbot/venv/lib/python3.11/site-packages/pycqBot/cqHttpApi.py", line 335, in cqhttp_start
    shell_msg = subp.stdout.readline().decode("utf-8").strip()
                ^^^^
UnboundLocalError: cannot access local variable 'subp' where it is not associated with a value
FengLiuFeseliud commented 1 year ago

我的问题,忘加 macos 了

bm567 commented 1 year ago

我的问题,忘加 macos 了

        def cqhttp_start():
            self._set_config(go_cqhttp_path)
            plat = platform.system().lower()
            if plat == 'windows':
                subp = subprocess.Popen("cd %s && .\go-cqhttp.exe -faststart" % go_cqhttp_path, shell=True, stdout=subprocess.PIPE)
            elif plat == 'linux':
                subp = subprocess.Popen("cd %s && ./go-cqhttp -faststart" % go_cqhttp_path, shell=True, stdout=subprocess.PIPE)
            elif plat == 'darwin':
                subp = subprocess.Popen("cd %s && ./go-cqhttp -faststart" % go_cqhttp_path, shell=True, stdout=subprocess.PIPE)

尝试手动添加mac系统,运行了下没报错