我怎样才能仅在1次霜中以及在rhat kill rhe函数之后调用和使用此功能?
调用函数:
else if (msg.text == ["📠contact us📠"]) {
const opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: arrangeKeyboard(locale.keyboards[msg.text].childs, 2, msg),
resize_keyboard: true,
one_time_keyboard: true
})
};
bot.sendMessage(msg.chat.id, "Please Write your Messages:", opts);
getmessage1();
}
这是我的函数,我不想循环运行,我需要发送一条消息并杀死函数。
var getmessage = async () => {
// Listen for any kind of message. There are different kinds of messages.
await new Promise((resolve, reject) => {
bot.on('message', (msg) => {
if (!locale.keyboards[msg.text] &&
!msg.text.includes("previous button")) {
console.log("user message is: " + msg.text)
const opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: arrangeKeyboardWithOut(locale.keyboards["/start"].childs, 2, msg),
resize_keyboard: true,
one_time_keyboard: true
})
};
bot.sendMessage(msg.chat.id, ' your message recieved', opts);
}
resolve(true);
});
});
return
}
var getmessage1 = async () => {
await getmessage();
}
最佳答案
您只需将bot.on
更改为bot.once
这样,bot对象将仅侦听事件一次,然后从侦听器范围中分离出来。