【问题标题】:Delete specific embed in user message with discord js (or display properly stored embed)使用不和谐 js 删除用户消息中的特定嵌入(或显示正确存储的嵌入)
【发布时间】:2021-06-30 06:45:14
【问题描述】:

在注意到 discord 上的 deviantArt 嵌入非常糟糕后,我决定在我的机器人中创建一个功能,该功能可以检测带有事件的 deviantart url 并发送更好的嵌入。

如果消息中有多个 url,它会检测 DeviantArt 并发送它们的嵌入(机器人)。

我的问题是,有时,在同一条消息(用户)中,一些 DA url 嵌入了 show 而有些则没有。所以我想只删除 Deviantart 嵌入以保留 ArtStation。

但我在 Discord js 上找到的唯一内容是 message.suppressEmbeds(true),它会删除所有嵌入的消息。

我尝试使用message.edit(),但对于消息的非作者来说,它是未经授权的。

我还尝试遍历所有嵌入并将所有不属于 DeviantArt 的 url 存储在一个数组中。所以我可以在运行message.suppressEmbeds(true) 后重新发送它们,但重新发送的版本看起来有些不同。我还是不明白为什么

var messageEmbed = [];
var index = 0;
for(var embed of msg.embeds){
     
  if(!embed.url.includes("www.deviantart.com")){ 
      messageEmbed[index]  = new Discord.MessageEmbed(embed);
      //also tried with
      //messageEmbed[index]  = embed; it does the same thing
      index++;
  } 
}

Image of what it looks like

我需要:

  • 找到删除特定嵌入消息(用户)的方法。
  • 找到一种方法来正确显示存储的嵌入。

【问题讨论】:

    标签: javascript api discord.js


    【解决方案1】:

    无法抑制单个嵌入。

    但你可以保存所有嵌入:

    const embeds = message.embeds;
    

    然后抑制嵌入:

    message.suppressEmbeds(true);
    

    然后再次发送每个嵌入,检查是否要替换它们。

    for (let embed of embeds) {
    
     let modifiedEmbed = new Discord.MessageEmbed(embed);
    
     if (embed.url === "deviantArtURL") {
    
      // Modify the embed embed
    
     }
    
     message.channel.send(embed);
    
    }
    

    很遗憾,没有其他办法。

    【讨论】:

      猜你喜欢
      • 2020-12-27
      • 2021-06-26
      • 2021-12-03
      • 2019-10-11
      • 2020-07-09
      • 2021-10-06
      • 2020-11-10
      • 2020-09-07
      • 2022-01-14
      相关资源
      最近更新 更多