Bug Fix: Chunk messages if response is too large
This commit is contained in:
parent
30e07afa85
commit
3da598c218
14
llamabot.js
14
llamabot.js
@ -149,7 +149,21 @@ client.on('messageCreate', async (message) => {
|
|||||||
|
|
||||||
if (response && response.trim()) {
|
if (response && response.trim()) {
|
||||||
// Send response to user if it's not empty
|
// Send response to user if it's not empty
|
||||||
|
const limit = 1980;
|
||||||
|
|
||||||
|
// if we are over the discord char limit we need chunks...
|
||||||
|
if (response.length > limit) {
|
||||||
|
const chunks = response.match(new RegExp(`.{1,${limit}}`, "g"));
|
||||||
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
|
setTimeout(() => {
|
||||||
|
message.channel.send(chunks[i]);
|
||||||
|
}, i * 3000); // delay of 3 seconds between each chunk to save on API requests
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We are good to go, send the response
|
||||||
await message.channel.send(response);
|
await message.channel.send(response);
|
||||||
|
}
|
||||||
|
|
||||||
setPresenceOnline()
|
setPresenceOnline()
|
||||||
setBusy(message.author.id, false);
|
setBusy(message.author.id, false);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user