[英]How to send messages to all telegram bot users from a list of ids in a database at once using npm library Telegraf
i have selected all ids of my telegram bot users from mysql database and want to send messages to them at once.I have tried我已经从 mysql 数据库中选择了我的电报机器人用户的所有 ID,并希望立即向他们发送消息。我试过了
con.query("SELECT id FROM account",function (err,res) {
res.forEach(function (message) {
ctx.telegram.sendMessage(message.id, ctx.message.text)
})
})
but it sends each message to a user at a time.i want to send the message to all users at once using an array of all ids as in telegram api但它一次将每条消息发送给一个用户。我想使用电报 api 中的所有 id 数组一次将消息发送给所有用户
Use sleep in your loop to send for each user:在循环中使用 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);
})
})
}
Good luck;祝你好运;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.