mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-05-23 05:29:43 +08:00
1.8 KiB
1.8 KiB
WeChatVersionNotMatchError异常
如果出现ntchat.exception.WeChatVersionNotMatchError
异常, 请确认是否安装github上指定的微信版本,如果确认已经安装,还是报错,可以在代码中添加以下代码,跳过微信版本检测
import ntchat
ntchat.set_wechat_exe_path(wechat_version='3.6.0.18')
如何多开
新建多个ntchat.WeChat实例,然后调用open方法:
import ntchat
# 多开3个微信
for i in range(3):
wechat = ntchat.WeChat()
wechat.open(smart=False)
更完善的多实例管理查看fastapi_example例子
如何监听输出所有的消息
# 注册监听所有消息回调
@wechat.msg_register(ntchat.MT_ALL)
def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
print("########################")
print(message)
完全例子查看examples/msg_register_all.py
如何关闭NtChat的日志
os.environ['NTCHAT_LOG'] = "ERROR"
要在import ntchat
前执行
# -*- coding: utf-8 -*-
import os
import sys
import time
os.environ['NTCHAT_LOG'] = "ERROR"
import ntchat
如何正常的关闭Cmd窗口
先使用pip install pywin32
安装pywin32模块, 然后在代码中添加以下代码, 完整例子查看examples/cmd_close_event.py
import sys
import ntchat
import win32api
def on_exit(sig, func=None):
ntchat.exit_()
sys.exit()
# 当关闭cmd窗口时
win32api.SetConsoleCtrlHandler(on_exit, True)
pyinstaller打包exe
使用pyinstaller打包NtChat项目,需要添加--collect-data=ntchat
选项
打包成单个exe程序
pyinstaller -F --collect-data=ntchat main.py
将所有的依赖文件打包到一个目录中
pyinstaller -y --collect-data=ntchat main.py