【发布时间】:2021-02-04 17:35:23
【问题描述】:
我想知道他们是否可以编辑已发送的嵌入字段。我想用参加嵌入活动的人员列表更新一个名为参与者的字段。有没有办法访问之前发送的嵌入来编辑这个字段,或者我只需要构建一个新的嵌入,然后使用 .edit 方法就可以了。我还注意到我可以使用像这样的行 const receivedEmbed = message.embeds[0]; 来访问嵌入在它所在的任何索引处,但文档说这可能会与缓存 (doc reference) 混淆。
这是我的代码的 sn-p 供参考
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
有什么建议或指示吗?我更多的是寻找有关执行此操作的逻辑的示例或解释,而不是我的代码的解决方案,因为我想尝试自己编写它:)。
感谢您提供的任何帮助!
【问题讨论】:
-
你需要创建一个嵌入对象,在频道中发送,当你得到一个反应时修改嵌入对象,然后用新修改的嵌入编辑消息。
标签: javascript discord discord.js