如果你按下上传照片按钮一次,机器人将发送照片1次。但是,如果你按下这个按钮超过1次,照片将发送给你多次按下这个按钮之前。包括点击的次数之前,以前的照片被发送
const keyboard = {
reply_markup:{
keyboard: [
[{text: 'About Bot'}, {text: 'Upload Photo'}]
]
}
}
bot.onText(/\/start/, async msg => {
await bot.sendMessage(h.id(msg), `Choose any`,keyboard)
})
bot.on('message', msg => {
switch (msg.text){
case 'Upload Photo':
uploadPhoto(h.id(msg))
break
case 'About Bot':
break
}
})
const uploadPhoto = async (chatId) => {
await bot.sendMessage(chatId, 'Send me a photo')
bot.on('photo', async (msg) => {
const photo = msg.photo[2].file_id
await bot.sendPhoto(channelId, photo)
await bot.sendMessage(chatId, 'Photo is sent')
})
}
按下按钮并成功发送照片后,下一张照片应仅出现一次
1条答案
按热度按时间esyap4oy1#
在
uploadPhoto()
末尾插入:bot.removeAllListeners('photo')
。这应该可以修复它。