一次发送多个嵌入

asd*_*asd 1 javascript node.js discord.js

当用户输入特定命令时,我试图一次发送多个嵌入(更具体地说,仅2个)。原因是我想要打印的信息只要嵌入1个,就会看起来很长。我听说这只能使用webhooks来完成,因为不和谐的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
Run Code Online (Sandbox Code Playgroud)

如您所见,我也在使用丰富的嵌入,但是我认为这对我尝试执行的操作没有任何影响。我曾尝试查找如何正确使用Webhook来执行此操作,但我什至勉强声明了我的钩子。如果能就我要完成的工作获得帮助,我将不胜感激(如果实际上有一种无需使用网络钩子就能做到这一点的方法,我一定乐于听到!)

Blu*_*her 5

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

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);
    });
}
Run Code Online (Sandbox Code Playgroud)

如您所见,在发送第二个嵌入之前,我等待第一个嵌入成功发送并等待诺言返回。您在尝试此类操作时是否遇到错误?