Handle Cleverbot errors.

This commit is contained in:
Dragon Fire
2021-03-07 20:51:49 -05:00
parent b8c8ea9422
commit 9a8d084bb4
+15 -4
View File
@@ -162,10 +162,21 @@ client.on('message', async msg => {
if (cleverbot) {
if (!cleverbot.shouldRespond(msg)) return;
msg.channel.startTyping().catch(() => null);
const response = await cleverbot.respond(msg.cleanContent);
msg.channel.stopTyping(true);
await msg.channel.send(response);
return;
try {
const response = await cleverbot.respond(msg.cleanContent);
msg.channel.stopTyping(true);
await msg.channel.send(response);
return;
} catch (err) {
msg.channel.stopTyping(true);
if (err.status === 503) {
await msg.channel.send('Monthly API limit reached. Ending conversation.');
client.cleverbots.delete(msg.channel.id);
return;
}
await msg.channel.send('Sorry, blacked out there for a second. Come again?');
return;
}
}
// Phone message handler