From 581edd0c43aec9a5562ad4f5bc8f189953418646 Mon Sep 17 00:00:00 2001 From: iTzArshia Date: Thu, 28 Sep 2023 18:05:49 +0330 Subject: [PATCH] Update messageCreate.js --- events/messageCreate.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/events/messageCreate.js b/events/messageCreate.js index f39dac8..310a2eb 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -303,7 +303,6 @@ module.exports = async (client, message) => { }).then(async (response) => { - let fullAnswer = ""; let answer = ""; let newMessage = message; @@ -312,6 +311,8 @@ module.exports = async (client, message) => { if (part.choices[0]?.finish_reason === 'stop') { + await message.channel.sendTyping(); + const newDataArray = [ { "role": "user", @@ -347,15 +348,29 @@ module.exports = async (client, message) => { } else { - if (answer.includes('\n\n') && answer.length <= 2000) { + if (answer.includes('\n\n')) { await message.channel.sendTyping(); - newMessage = await newMessage.reply({ content: answer }); - answer = ""; + if (answer.length <= 2000) { + + newMessage = await newMessage.reply({ content: answer }); + + } else { + const attachment = new Discord.AttachmentBuilder( + Buffer.from(answer, 'utf-8'), + { name: 'response.txt' } + ); + + await newMessage.reply({ files: [attachment] }); + + }; + + answer = ""; await func.delay(5000); + }; answer += part.choices[0]?.delta?.content || '';