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:
parent
2a38ae4a95
commit
dffb13361c
1 changed files with 14 additions and 8 deletions
|
@ -18,14 +18,20 @@ export default class Moderation {
|
|||
return true;
|
||||
}
|
||||
|
||||
const answer = await openai.createModeration({
|
||||
input: formatMessage(message),
|
||||
});
|
||||
try{
|
||||
const answer = await openai.createModeration({
|
||||
input: formatMessage(message),
|
||||
});
|
||||
|
||||
const flagged = answer.data.results[0].flagged;
|
||||
this.cache.set(message.id, flagged);
|
||||
if (flagged) message.react("⚠");
|
||||
const flagged = answer.data.results[0].flagged;
|
||||
this.cache.set(message.id, flagged);
|
||||
if (flagged) message.react("⚠");
|
||||
|
||||
return flagged;
|
||||
return flagged;
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue