当用户输入某个命令时,我尝试一次发送多个嵌入(更具体地说,只有 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
如您所见,我还使用了丰富的嵌入,但我认为这对我想做的事情没有任何影响。我尝试查找如何正确使用网络钩子(Hook)来执行此操作,但我什至几乎没有设法声明我的钩子(Hook)。如果我能获得关于如何去做我想要完成的事情的帮助,我将不胜感激(如果实际上有一种方法可以在不使用网络钩子(Hook)的情况下做到这一点,无论如何我很乐意听到了!)
最佳答案
您可以将多个嵌入内容发送到同一 channel ,我不确定谁告诉您这是不可能的。这是我正在使用的代码,它成功地将多个嵌入发送到 channel :
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);
});
}
如您所见,我等待第一个嵌入成功发送并等待 promise 返回,然后再发送第二个嵌入。您在尝试此类操作时是否遇到错误?
关于javascript - 一次发送多个嵌入内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48614541/