javascript - 兑现承诺
问题描述
我正在尝试查找频道中的消息是否仍然存在,但是,我不确定如何解决承诺,查看其他答案和文档我可以看到它可能是通过一个函数,但我不完全确定关于如何去做。我希望能得到一些帮助,因为这是我的 Discord 机器人新功能的最后一步。
const embedId = embedChannel.messages.fetch(foundtEmbed.ticketembedchan);
console.log(embedId)
目前输出Promise { <pending> }
解决方案
您应该使用async/await
或使用then
:
try {
const embedId = await embedChannel.messages.fetch(foundtEmbed.ticketembedchan);
console.log(embedId)
}catch(err) {
console.log(err)
}
不要忘记添加async
到您的功能。或者:
embedChannel.messages.fetch(foundtEmbed.ticketembedchan)
.then(res => console.log(res))
.catch(err => console.log(err))
推荐阅读
- python - 使用熊猫根据字符串和附加列聚合数量
- amazon-web-services - HTTP ERROR 500 While try to connect to RDS in EC2
- java - Java NIO WatchService
- tree - Non-tree model error when using xgbTree method with Caret and weights to target variable when applying the varImp function
- java - Android, background service with UI manager
- c# - docker-compose app container can't connect to mongo container
- c# - Do AsyncLocal<> values need to be thread-safe?
- c# - How can I bind the Window title to a string
- powershell - How to get certificate from Azure KeyVault as .crt and .key files?
- firebase - Firebase notifications message with emojis in Flutter