如何使用 npm 库 Telegraf 一次从数据库中的 ID 列表向所有电报机器人用户发送消息

How to send messages to all telegram bot users from a list of ids in a database at once using npm library Telegraf

我已经从 mysql 数据库中选择了我的电报机器人用户的所有 ID,并希望在 once.I 向他们发送消息已尝试

con.query("SELECT id FROM account",function (err,res) {
           res.forEach(function (message) {
               ctx.telegram.sendMessage(message.id, ctx.message.text)
   })
})

但它会将每条消息发送给 time.i 的用户 想要使用电报中的所有 ID 数组一次将消息发送给所有用户 api

在循环中使用 sleep 为每个用户发送:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function send() {
   con.query("SELECT id FROM account",function (err,res) {
       res.forEach(function (message) {
           ctx.telegram.sendMessage(message.id, ctx.message.text)
           await sleep(2000);
      })
   })
 }

祝你好运;