0
我想在下面的代碼中使用async/await。JS調用嵌套的異步函數
在if/else
部分,它驗證正確,但嵌套函數不會被調用。
該代碼僅在if/else
完成後停止。
難道有人會對此發光嗎?謝謝。異步功能
if (q1.value === 'yes') {
await askQuestion()
} else {
await endConvo()
}
因爲askQuestion()和endConvo()是異步的功能,在程序退出之前
async function initBot() {
await botui.message.bot({
content: `Do you have any questions?`
})
let q1 = await botui.action.button({
action: [{
text: 'Yes',
value: 'yes'
}, {
text: 'No',
value: 'no'
}]
})
// This is where it's stuck
if (q1.value === 'yes') {
askQuestion()
} else {
endConvo()
}
let endConvo = async() => {
await botui.message.bot({
content: `END`
})
}
let askQuestion = async() => {
await botui.message.bot({
content: `What's your questions?`
})
}
}
export default initBot
對我不起作用 – shawnl
函數未被調用? – marvel308