0
votes

For the past few days I've been trying to make a command where it reacts to a message with a custom emote. It gives me an error in the console saying this:

TypeError [EMOJI_TYPE]: Emoji must be a string or GuildEmoji/ReactionEmoji
    at Message.react (E:\Projects\DiscordBots\node_modules\discord.js\src\structures\Message.js:546:23)
    at Client.<anonymous> (E:\Projects\DiscordBots\LordMoth\moth.js:98:17)
    at Client.emit (events.js:327:22)
    at MessageCreateAction.handle (E:\Projects\DiscordBots\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (E:\Projects\DiscordBots\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (E:\Projects\DiscordBots\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (E:\Projects\DiscordBots\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (E:\Projects\DiscordBots\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (E:\Projects\DiscordBots\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:315:20) {
  [Symbol(code)]: 'EMOJI_TYPE'
}

I've tried the answers from How Find Emojis By Name In Discord.js and Emoji must be a string or Emoji/ReactionEmoji from getting a custom emote but no luck. I'm also sending the message in a channel from the guild where the emote is from.

My current code:

client.on("message", message => {
    if (message.content === "ok") {
        const mfi = message.guild.emojis.cache.find(emoji => emoji.name === "MOTHIFEST");
        message.react(mfi);
    }
});

And another solution I've tried to do with the emote's ID that's actually in the discord.js documentation (https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=react):

client.on("message", message => {
    if (message.content === "ok") {
        message.react(message.guild.emojis.cache.get("824436212034830356"));
          .then(console.log)
          .catch(console.error);
    }
});

I'm confused so much. Please help me.

1
Have you tried to log what the value of mfi is?Zsolt Meszaros
@ZsoltMeszaros I've just tried that now, and it's still giving me the same exact error.user11909561
Well, yeah, you should comment out message.react(mfi) then :) You could also log a list of emoji names and ids using this: message.guild.emojis.cache.each((e) => console.log(${e.id}: ${e.name})) so you could see if the one you're looking for exists.Zsolt Meszaros

1 Answers

0
votes

Make sure the emoji name is correct. Don't forget that it's case sensitive. Try to check the value of mfi and only react to the message if it's not undefined:

client.on('message', (message) => {
  if (message.content === 'ok') {
    const mfi = message.guild.emojis.cache.find((emoji) => emoji.name === 'MOTHIFEST');

    if (mfi) {
      message.react(mfi);
    }
  }
});

As message.react returns a promise you could also use catch to catch any errors:

const mfi = message.guild.emojis.cache.find((emoji) => emoji.name === 'MOTHIFEST');

message
  .react(mfi)
  .then(() => console.log('Reaction sent'))
  .catch((err) => console.log(`Oops, there was an error ${err}`));

You could also log a list of emoji names and ids using the following example, so you could see if the one you're looking for exists:

message.guild.emojis.cache.each((e) => console.log(${e.id}: ${e.name}))