首页 > 解决方案 > 获取我的机器人发送的消息的消息 ID

问题描述

我需要获取我的不和谐机器人发送的消息的消息 ID(它发送丰富的嵌入)

谢谢

标签: javascriptnode.jsdiscord.js

解决方案


当您使用(或Discord.js 中TextChannel.send()的任何其他类型)时,它会返回一个Promise,该 Promise 会使用您刚刚发送的消息进行解析。 要使用该消息,您可以使用将其存储在变量中,也可以使用并将其余代码作为函数传递。.send
awaitPromise.then()

这是一个例子:

// with async/await:
async function replyAndLog() {
  let sent = await message.reply("Your stuff..."); // this returns the message you just sent
  let id = sent.id; // you can get its ID with <Message>.id, as usually
  console.log(id);
}

// with <Promise>.then():
message.reply("Your stuff").then(sent => { // 'sent' is that message you just sent
  let id = sent.id;
  console.log(id);
});

推荐阅读