为什么 Telegraf.js 的 Telegram Bot 的 bot.reaction() 不起作用?

问题描述 投票:0回答:1

尝试使用 Telegraf.js 开发电报机器人,当我尝试监听消息反应时,代码不起作用。 该代码与 Telegraf 4.16.0 发行说明 - 使用反应

相同

我的演示代码:

const {Telegraf} = require('telegraf');

const dotenv = require('dotenv');

// Load DOTENV
dotenv.config();
// Config
const BOT_TOKEN = process.env.BOT_TOKEN || '';
// Init bot
const bot = new Telegraf(BOT_TOKEN);

bot.reaction("👍", (ctx) => {
    // user added a 👍 reaction
    console.log("added")
});

bot.launch();
console.log(`Launch local with token: ${BOT_TOKEN}`)

package.json - 依赖项

"dependencies": {
    "dayjs": "^1.11.7",
    "dotenv": "^16.0.3",
    "mongodb": "^4.13.0",
    "rss-parser": "^3.12.0",
    "telegraf": "^4.16.3"
  }

我尝试过特定版本 4.16.0 和其他方式,如

bot.on('message_reaction')
但发生了什么事 感谢您的帮助。

node.js telegram telegram-bot telegraf telegraf.js
1个回答
0
投票

这里遇到了同样的问题,结果默认情况下,Telegram 不发送反应,你必须启用它。

// enable updates from reactions
bot.launch({ allowedUpdates: [ "message", "message_reaction" ] });
© www.soinside.com 2019 - 2024. All rights reserved.