【发布时间】:2023-03-17 01:00:01
【问题描述】:
我正在编写一个电报机器人(使用 Telegraf),需要以特定的顺序以一定的时间间隔发送 3 条消息。然后我在 VC 代码中运行这段代码,它运行良好。当我在服务器 (AWS) 上部署相同的代码时,它就不起作用了。我没有从 setTimeout 函数得到任何输出。
const executeAfterGivenTime = (func, time) => new Promise(res => setTimeout(() => res(func()), time));
function newOne(ctx){
ctx.reply('coo');
}
function newTwo(ctx){
ctx.reply('boo');
}
function newThree(ctx){
ctx.reply('foo');
}
bot.command('dit', async (ctx) => {
await executeAfterGivenTime(() => newOne(ctx), 0);
await executeAfterGivenTime(() => newTwo(ctx), 6000);
await executeAfterGivenTime(() => newThree(ctx), 12000);
})
【问题讨论】:
-
我得到“coo”,但没有得到“boo”和“foo”。
-
指定您使用的机器人库。
-
@KevinWelch Telegraf
标签: javascript settimeout telegram-bot telegraf