尝试使用 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')
但发生了什么事
感谢您的帮助。
这里遇到了同样的问题,结果默认情况下,Telegram 不发送反应,你必须启用它。
// enable updates from reactions
bot.launch({ allowedUpdates: [ "message", "message_reaction" ] });