安装

nonebot:(Python >= 3.7)

pip3 install nonebot

go-cqhttp:

  1. 下载:
wget https://github.com/Mrs4s/go-cqhttp/releases/download/v0.9.32/go-cqhttp-v0.9.32-linux-amd64.tar.gz
  1. 解压:
tar -zxvf go-cqhttp-v0.9.32-linux-amd64.tar.gz
  1. 首次运行:
./go-cqhttp
  1. 编辑config.hjson:
vim config.hjson

以下为需要修改的参数:

uin: qq号
password = "qq密码"
ws_reverse_servers: [
        {
            enabled: true
            reverse_url: ws://127.0.0.1:7070/ws
        }
    ]

机器人自动回复设置

bot.py

from os import path
import nonebot
import config

if __name__ == '__main__':
    nonebot.init(config)
    nonebot.load_plugins(
        path.join(path.dirname(__file__), 'awesome', 'plugins'),
        'awesome.plugins'
    )
    nonebot.run()

config.py

from nonebot.default_config import *

HOST = '0.0.0.0'
PORT = 7070

NICKNAME = {''}
COMMAND_START = {''}

__init__.py

from nonebot import on_command, CommandSession
from nonebot import on_natural_language, NLPSession, IntentCommand

@on_natural_language(keywords={'keyword1', 'keyword2'})
async def autoResponse(session: NLPSession):
    stripped_msg = session.msg_text.strip()
    qq = session.event.user_id
    auto_report = '''自动回复的内容'''
    at = '[CQ:at,qq={}]'.format(qq)
    await session.send(at + auto_report)
    print(stripped_msg)

启动机器人

  1. 后台运行python文件:
nohup python3 bot.py &
  1. 后台运行go-cqgttp:
nohup ./go-cqhttp &

完成!

最后修改:2023 年 08 月 26 日
如果觉得我的文章对你有用,请随意赞赏