Error in Discord.js Bot: `message.react()` Function Is Undefined

I’ve created a Discord bot for my server that is supposed to add reactions to messages. Everything is running smoothly until a message is sent, at which point it errors out.

The error I receive is:

TypeError: message.react is not a function
    at DiscordClient.bot.on (/path/to/bot.js:22:6)

Here’s the code I’m using:

const Discord = require("discord.io");
const logger = require("winston");
const auth = require("./auth.json");

// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console(), {
  colorize: true,
});
logger.level = "debug";

// Initialize Discord Bot
const bot = new Discord.Client({
  token: auth.token,
  autorun: true,
});
bot.on("ready", function (evt) {
  logger.info("Connected");
  logger.info("Logged in as: ");
  logger.info(bot.username + " - (" + bot.id + ")");
});
bot.on("message", (message) => {
  message.react("🍎");
});

I’m using version 12.2.0 of discord.js. Can someone point out what I am doing wrong?

I ran into this exact same problem when I first started working with Discord bots. The confusion comes from having both discord.io and discord.js installed simultaneously. Even though you think you’re using discord.js, your require statement is pulling in discord.io which doesn’t support the react method. After fixing the import, you might also need to uninstall discord.io completely with npm uninstall discord.io to avoid future conflicts. When I had both packages installed, it caused intermittent issues even after correcting the require statement. Also worth noting that the message object structure differs between the two libraries, so other methods might fail as well if you don’t clean up the old package.

The problem stems from mixing up two different libraries. You’re importing discord.io but trying to use discord.js methods. The discord.io library has been deprecated for years and lacks many modern features including the react function. Since you mentioned using discord.js version 12.2.0, you need to change your import statement to match. Replace const Discord = require("discord.io"); with const Discord = require("discord.js"); and make sure you have the correct package installed. Also, with discord.js v12, you’ll want to use const { Client } = require('discord.js'); and const bot = new Client(); instead of Discord.Client for better practice. This should resolve your undefined function error immediately.

youre using discord.io not discord.js - thats the issue. discord.io is outdated and doesnt have the react method. switch to discord.js with npm install discord.js and update your require to const Discord = require('discord.js'). should fix it right up