Update bot to new discord API and add simple chatgpt module

This commit is contained in:
2023-03-21 13:35:28 +01:00
parent 136173f4de
commit b6008e0ad3
11 changed files with 6383 additions and 4183 deletions

20
modules/chatgpt/index.js Normal file
View File

@@ -0,0 +1,20 @@
let ChatGPTAPI = null;
module.exports = function (bot, api) {
import("chatgpt").then((mod) => {
ChatGPTAPI = mod.ChatGPTAPI;
});
api.registerCommand('chat', async (args, message) => {
const response = await getChatGPTResponse(message.content.slice(6).trim());
api.respond(message, response);
});
}
async function getChatGPTResponse(prompt) {
const api = new ChatGPTAPI({
apiKey: process.env.OPENAI_API_KEY
})
const res = await api.sendMessage(prompt);
return res.text;
}