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
|
@ -17,15 +17,21 @@ export default class Moderation {
|
||||||
this.cache.set(message.id, true);
|
this.cache.set(message.id, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
const answer = await openai.createModeration({
|
||||||
|
input: formatMessage(message),
|
||||||
|
});
|
||||||
|
|
||||||
const answer = await openai.createModeration({
|
const flagged = answer.data.results[0].flagged;
|
||||||
input: formatMessage(message),
|
this.cache.set(message.id, flagged);
|
||||||
});
|
if (flagged) message.react("⚠");
|
||||||
|
|
||||||
const flagged = answer.data.results[0].flagged;
|
return flagged;
|
||||||
this.cache.set(message.id, flagged);
|
}
|
||||||
if (flagged) message.react("⚠");
|
catch (e) {
|
||||||
|
console.log(e);
|
||||||
return flagged;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue