2 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
您是const budget在不同于全局范圍的范圍內(nèi)定義 的(有關(guān)范圍,請參閱此頁面)。
這個(gè)答案解釋了聲明、變量和范圍如何協(xié)同工作。
在這里,您budget僅在awaitMessages.then范圍內(nèi)可用,即
.then(messages => {
msg.channel.send(`You've entered: ${messages.first().content}`);
const budget = messages.first().content;
// the const is only know there
})
但是,該then塊將返回一個(gè)值。因?yàn)椴辉儆墟準(zhǔn)匠兄Z(除非有錯(cuò)誤,因?yàn)樗鼤|發(fā)鏈?zhǔn)絚atch)。在此處了解有關(guān) promise 的更多信息。
有用的是,一旦承諾被解決,msg.channel.awaitMessages將返回一個(gè)值。
然后你可以做兩件事:
等待 的響應(yīng)msg.channel.awaitMessages,將其分配給變量并稍后使用
鏈接另一個(gè)承諾
等待:
let budget = await msg.channel.awaitMessages(filter, { time: 60000, maxMatches: 1, errors: ['time'] })
.then(messages => {
msg.channel.send(`You've entered: ${messages.first().content}`);
return messages.first().content;
})
.catch(() => {
msg.channel.send('You did not enter any input!');
});
});
if (messageReaction.emoji.name === reactions.one) {
let web = new Discord.RichEmbed()
.setDescription("Press the check to claim the comission")
.setColor("#15f153")
.addField("Client", `${message.author} with ID: ${message.author.id}`)
.addField("Budget", `${budget}`)
.addField("Time", message.createdAt)
.addField("Requested Freelancer",`<@&603466765594525716>`)
let tickets = message.guild.channels.find('name', "tickets")
if(!tickets) return message.channel.send(`${message.author} Can't find tickets channel.`)
// ...
}
鏈接:
msg.channel.awaitMessages(filter, { time: 60000, maxMatches: 1, errors: ['time'] })
.then(messages => {
msg.channel.send(`You've entered: ${messages.first().content}`);
return messages.first().content;
})
.then((budget) => {
if (messageReaction.emoji.name === reactions.one) {
let web = new Discord.RichEmbed()
.setDescription("Press the check to claim the comission")
.setColor("#15f153")
.addField("Client", `${message.author} with ID: ${message.author.id}`)
.addField("Budget", `${budget}`)
.addField("Time", message.createdAt)
.addField("Requested Freelancer",`<@&603466765594525716>`)
let tickets = message.guild.channels.find('name', "tickets")
if(!tickets) return message.channel.send(`${message.author} Can't find tickets channel.`)
// ...
}
})
.catch(() => {
msg.channel.send('You did not enter any input!');
});
添加回答
舉報(bào)