If anyone needs it; I made a code sample of how to deal with flagged prompts.
const response = await openai.createModeration({
model: 'text-moderation-latest',
input: prompt,
})
if (response.data.results[0].flagged) {
let array = []
if (response.data.results[0].categories['hate/threatening']) {
array.push('Hate/Threatning')
} else if (response.data.results[0].categories.hate) {
array.push('Hate')
}
if (response.data.results[0].categories['sexual/minors']) {
array.push('Sexual/Minors')
} else if (response.data.results[0].categories.sexual) {
array.push('Sexual')
}
if (response.data.results[0].categories['violence/graphic']) {
array.push('Violence/Graphic')
} else if (response.data.results[0].categories.violence) {
array.push('Violence')
}
if (response.data.results[0].categories['self-harm']) {
array.push('Self Harm')
}
if (array.length > 0) {
const flaggedEmbed = new Discord.EmbedBuilder()
.setColor('Red')
.setTitle('Flagged Search')
.setDescription(`Your search included \`${array.join(', ')}\``)
return interaction.editReply({ embeds: [flaggedEmbed] })
}
}
There might be better ways but this is just how I handle it.