javascript - 获取我的机器人发送的消息的消息 ID
问题描述
我需要获取我的不和谐机器人发送的消息的消息 ID(它发送丰富的嵌入)
谢谢
解决方案
当您使用(或Discord.js 中TextChannel.send()
的任何其他类型)时,它会返回一个Promise,该 Promise 会使用您刚刚发送的消息进行解析。
要使用该消息,您可以使用将其存储在变量中,也可以使用并将其余代码作为函数传递。.send
await
Promise.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);
});
推荐阅读
- varnish - 当通过我的 Varnish 服务器发出请求时,如何自定义向遇到 Guru Meditation 错误的用户显示的消息?
- sql-server - 在 SQL Server 中查找以下结果的查询
- python - 从嵌套字典到数据框的值映射无法正常工作
- python - 如何通过 Ansible Tower API 将可变数据传递到剧本模板
- git - 如何撤消 git 中的变基
- javascript - Mongoose 按键更新子文档
- docker - 无法访问 docker port actix web build
- c# - 根据 C# 中的值对列表进行排序
- javascript - Openlayers 典型边界外的矢量图层渲染坐标
- angular - 基于反应形式角度的条件生成表单控件