2 回答
TA贡献1785条经验 获得超8个赞
您是const budget在不同于全局范围的范围内定义 的(有关范围,请参阅此页面)。
这个答案解释了声明、变量和范围如何协同工作。
在这里,您budget仅在awaitMessages.then范围内可用,即
.then(messages => {
msg.channel.send(`You've entered: ${messages.first().content}`);
const budget = messages.first().content;
// the const is only know there
})
但是,该then块将返回一个值。因为不再有链式承诺(除非有错误,因为它会触发链式catch)。在此处了解有关 promise 的更多信息。
有用的是,一旦承诺被解决,msg.channel.awaitMessages将返回一个值。
然后你可以做两件事:
等待 的响应msg.channel.awaitMessages,将其分配给变量并稍后使用
链接另一个承诺
等待:
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!');
});
添加回答
举报