How to use setMessageReaction(node-telegram-bot-api)?

105 Views Asked by At

Getting error ETELEGRAM:

400 Bad Request: message to react not found

I am using the node-telegram-bot API and trying to set a reaction to a message in the channel via the setMessageReaction method:

bot.setMessageReaction method('@channel_name', message_id, [
{type: 'emoji', emoji: '' },
])

But I get the following error:

ETELEGRAM: 400 Bad Request: message to react not found

What could be the reason if the message id is correct?

2

There are 2 best solutions below

4
Makasin On BEST ANSWER

The problem isn't the permissions, but the emoji needs to be passed this way.

const reaction = [{ type: 'emoji', emoji: '' }];

bot.setMessageReaction(chatId, messageId, {reaction: JSON.stringify(reaction)})
3
Aariyan Patel On

Your bot needs to have the necessary permissions to add reactions in the target chat.

const TelegramBot = require('node-telegram-bot-api');

const token = 'YOUR_BOT_TOKEN';
const bot = new TelegramBot(token, { polling: true });

const chatId = 123456789;
const messageId = 123; 

const reaction = [{ type: 'emoji', emoji: '' }]; 

bot.setMessageReaction(chatId, messageId, reaction)
  .then(() => {
    console.log('Reaction added successfully!');
  })
  .catch(error => {
    console.error('Error adding reaction:', error);
  });