首页 > 解决方案 > 兑现承诺

问题描述

我正在尝试查找频道中的消息是否仍然存在,但是,我不确定如何解决承诺,查看其他答案和文档我可以看到它可能是通过一个函数,但我不完全确定关于如何去做。我希望能得到一些帮助,因为这是我的 Discord 机器人新功能的最后一步。

    const embedId = embedChannel.messages.fetch(foundtEmbed.ticketembedchan);

console.log(embedId)目前输出Promise { <pending> }

标签: javascriptdiscord.js

解决方案


您应该使用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))

推荐阅读