javascript - 编辑嵌入字段的正确方法
问题描述
我想知道他们是否是一种编辑已发送的嵌入字段的方法。我想用参加嵌入活动的人员列表更新一个名为参与者的字段。有没有办法访问之前发送的嵌入来编辑这个字段,或者我只需要构建一个新的嵌入,然后使用 .edit 方法就可以了。我还注意到我可以使用这样的行const receivedEmbed = message.embeds[0];
来访问嵌入在它所在的任何索引处,但是文档说这可能会混淆缓存(文档参考)。
这是我的代码片段供参考
var reactions = ['','','' ]; // Valid reactions for filter
var participants = []; // People attending the event
// Sending the embed back and then . . .
message.channel.send(eventEmbed)
.then(embedMessage => {
// Adding the reactions after the embed has been created
embedMessage.react("");
embedMessage.react("");
embedMessage.react("");
console.log(eventEmbed);
// Reaction Collector to gather the users attending the event.
const filter = (reaction, user) => {
return !user.bot && reactions.includes(reaction.emoji.name);
};
// The reactor is used to identify a new user that will be attending the event,
// and adding them to the list
rc = new Discord.ReactionCollector(embedMessage, filter);
rc.on('collect', (reaction, user) => {
console.log(user + " reacted with a " + reaction);
attendees.push(user); // Add new user the the attendees list
console.log(attendees); // Debugging
reaction.users.remove(user); // Reset reaction count back to 1
// Then here I want to edit the participants field with the new participants list
有什么建议或指示吗?我更多的是寻找有关执行此操作的逻辑的示例或解释,而不是我的代码的解决方案,因为我想尝试自己编写它:)。
我很感激可以提供的任何帮助!
解决方案
很难获取嵌入然后对其进行编辑。但是,有一种方法可以从预先存在的对象中编辑它。
您可以保留您的嵌入对象,当您想要更新某些内容时,转到对象的字段属性,获取您想要的字段,编辑该字段,然后将您的原始消息替换为新消息。
在你放的地方// Then here I want to edit the participants field with the new participants list
。你应该把
eventEmbed.fields.find(f => f.name === "attendees").value = attendees;
embedMessage.edit(eventEmbed);
推荐阅读
- docker - WixToolset 不能安装在具有 windows/servercore 基础映像的 windows 容器中
- oracle-data-integrator - 有没有一种方法可以在 ODI 元数据数据库中的某处找到数据存储对象上的强制执行上下文?
- spring-boot - 如何修复 XXX:jar:1.0 的 POM 丢失,没有可用的依赖信息
- tomcat - 如何在servlet容器(tomcat)中运行wiremock
- hyperledger-fabric - 生产模式下的 Hyperledger Fabric SDK 连接配置文件配置
- python - 在 Alexa Skills Kit 中了解插槽并获取其值
- javascript - 我如何检查字段是否填充了科尔多瓦/角度
- kubernetes - 在 pod 定义中使用图像哈希而不是标签
- python - 当地图在pygame中移动时用鼠标找到一个项目
- python - 如何在 python openshift rest 客户端中使用 load_incluster_config 时修复“没有这样的文件或目录:'/home/jenkins/.kube/config'”