I'm trying to make my Discord bot send an emoji when I tell it the name. E.g., say I send !emoji hello, I want the bot to send back the emoji called hello.
If I send an emoji the bot will send it back but I'm not sure how to grab an emoji from its name being sent to the bot.
I use discord.js v12 for reference.
You could try something like this
bot.on("messageCreate", (message) => {
const exampleEmoji = message.guild.emojis.cache.find(emoji => emoji.name === message.content);
channel.message.send(`Is this the emoji you want? ${exampleEmoji}`);
});
You can then nest it inside of your if statement as you please with whatever command you are using. This also should be v12/v13 compatible and I believe the only differences with older versions is whether you add cache or not to the find function.
You can also use the same function to find the emoji as a boolean to determine if the emoji exists or not and if not send a different message for feedback.
I also found this really interesting function which helped me when deciphering which emojis I have and which are not in the scope I am presenting.
if (message.content === "listemojis") {
const emojiList = message.guild.emojis.cache.map((e, x) => `${x} = ${e} | ${e.name}`).join("\n");
message.channel.send(emojiList);
}
Which will output this for every emoji within the scope you searched.
450661466287112204 = :image: | name
Which I found here. Hope this helps