Add try-catch in moderation when checking with moderation api

Now it won't crash the bot when the moderation api is not availabe (somehow)
This commit is contained in:
Wroclaw 2023-03-20 06:08:42 +01:00
parent 2a38ae4a95
commit dffb13361c

View file

@ -18,14 +18,20 @@ export default class Moderation {
return true; return true;
} }
const answer = await openai.createModeration({ try{
input: formatMessage(message), const answer = await openai.createModeration({
}); input: formatMessage(message),
});
const flagged = answer.data.results[0].flagged; const flagged = answer.data.results[0].flagged;
this.cache.set(message.id, flagged); this.cache.set(message.id, flagged);
if (flagged) message.react("⚠"); if (flagged) message.react("⚠");
return flagged; return flagged;
}
catch (e) {
console.log(e);
return false;
}
} }
} }