【问题标题】:Sending multiple embeds at once一次发送多个嵌入
【发布时间】:2018-07-14 20:02:47
【问题描述】:

当用户输入某个命令时,我正在尝试一次发送多个嵌入(更具体地说,只有 2 个)。原因是我想要打印的信息在 1 次嵌入中看起来会非常长。我听说这只能使用 webhook 来完成,因为 discord API 通常不允许这样做。所以下面的代码不起作用:

const embed = new Discord.RichEmbed()
.setAuthor("blah")
.addField("blah")
message.channel.send({embed}) // this will send fine

const embed2 = new Discord.RichEmbed()
.setAuthor("blah")
.addField("blah")
message.channel.send({embed2});   // This wont work

如您所见,我也在使用丰富的嵌入,但我认为这对我正在尝试做的事情没有任何影响。我已经尝试查找如何正确使用 webhook 来做到这一点,但我什至几乎没有设法声明我的钩子。如果我能就如何去做我想要完成的事情获得帮助,我将不胜感激(如果实际上有一种方法可以在不使用 webhook 的情况下做到这一点,无论如何我很乐意听听!)

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    我认为如果你使用会更好:

    message.channel.send(embed1, embed2)
    

    【讨论】:

      【解决方案2】:

      您可以将多个嵌入发送到同一个频道,我不确定谁告诉您这是不可能的。这是我正在使用的代码,它成功地将多个嵌入发送到一个频道:

      function send2Embeds(message) {
          let channel = message.channel;
      
          // next create rich embeds
          let embed1 = new Discord.RichEmbed({
              title: 'embed1',
              description: 'description1',
              author: {
                  name: 'author1'
              }
          });
      
          let embed2 = new Discord.RichEmbed({
              title: 'embed2',
              description: 'description2',
              author: {
                  name: 'author2'
              }
          });
      
          // send embed to channel
          channel.send(embed1)
          .then(msg => {
              // after the first is sent, send the 2nd (makes sure it's in the correct order)
              channel.send(embed2);
          });
      }
      

      如您所见,我等待第一个嵌入成功发送并等待承诺返回,然后再发送第二个嵌入。您在尝试这样的事情时遇到错误了吗?

      【讨论】:

      • 哦,原来如此!当我尝试使用 .addfield 等方法时它不起作用。它说我试图发送一条空消息。我在 discord.js 不和谐服务器中,我尝试在问题频道中搜索“发送多个嵌入”,从字面上看,每个回复都说你必须使用 webhook。因此,要么与我正在尝试做的事情以及他们正在谈论的事情存在误解,要么他们都错了。无论哪种方式,谢谢,这可以满足我的需要。
      • @SirOxorsid - 啊,很奇怪,也许您需要添加titledescription 而不仅仅是authorfield?很高兴这有帮助!
      猜你喜欢
      • 2022-01-24
      • 2019-04-03
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      • 2020-04-21
      • 2015-02-17
      相关资源
      最近更新 更多