I'm doing a command to translate every messages that have a certain reaction to the language of the flag emoji (the one that the user reacted with).
But I want the bot to only translate once for one language (if there's two users that react with the us flag, it will translate the message to English only once).
I can use the reaction filter, but in my case for a better code, I'm using a switch statement, so if I use the max property in the reaction filter, I wouldn't be able to translate multiple times a message (only once).
Here's my code :
bot.on('message', async (msg) => {
const reactionFilter = (reaction, user) => {
return msg.author.id !== '724682218454253588';
};
collector = msg.createReactionCollector(reactionFilter);
collector.on('collect', async (reaction, user) => {
switch (reaction.emoji.name) {
case '':
TranslateMessage(msg, 'fr');
break;
case '':
TranslateMessage(msg, 'en');
break;
case '':
TranslateMessage(msg, 'de');
break;
case '':
TranslateMessage(msg, 'es');
break;
case '':
TranslateMessage(msg, 'ja');
break;
}
});
});
(I have a lot more of langues than that in this switch statement, but for the question it's easier to read)
And here's the TranslateMessage function :
async function TranslateMessage(msg, lang) {
try {
const traduction = await traduire(msg.content, lang);
const MessEmbed = new MessageEmbed()
.setAuthor(msg.author.username, msg.author.avatarURL)
.setDescription(traduction);
return msg.channel.send(MessEmbed);
} catch (error) {
return msg.channel.send("There's an error, try again !");
}
}