QQ機(jī)器人:增加問題記錄功能 (續(xù)接cqhttp+nonebot+gpt3 QQ機(jī)器人視頻)
背景:
記錄群友罪證
方法:
1.在bot.py加入功能代碼
????
questions = [] ?# 定義一個(gè)空列表,用來存儲問題
@on_message
async def handle_message(bot, event):
? ? # 從消息中提取問題
? ? question = event.message.extract_plain_text()
? ? questions.append(question) ?# 將問題添加到列表中
? ?
? ? # 打開文件,如果文件不存在則自動(dòng)創(chuàng)建
? ? with open('questions.txt', 'a') as f:
? ? ? ? # 將問題寫入文件,并換行
? ? ? ? f.write(questions[-1] + '\n')

2.導(dǎo)入所需的模塊(python語言)
from nonebot import on_message

標(biāo)簽: