diff --git a/Xiao.js b/Xiao.js index 32ba4daf..1740732d 100644 --- a/Xiao.js +++ b/Xiao.js @@ -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