[英]Discord.js Button on Embed
我想让它发送一个嵌入而不是说“如果你想申请,请单击下面的按钮。”,并在嵌入下方有应用按钮我已经阅读了一些关于组件数组和嵌入数组的东西,但我可以似乎没有任何工作如果有人可以帮助我,我将不胜感激
两个非常有帮助的人帮助了我
@Skulaurun Mrusal和@PerplexingParadox
谢谢!
client.on("message", async (message) => {
// Don't reply to bots
if (message.author.bot) return;
if (message.content == "#req") {
if(!message.member.hasPermission("MANAGE_MESSAGES"))
{
message.reply("You do not have permission to do that!");
return;
}
// Perform raw API request and send a message with a button,
// since it isn't supported natively in discord.js v12
client.api.channels(message.channel.id).messages.post({
data: {
embeds: [reqEmbed],
components: [
{
type: 1,
components: [
{
type: 2,
style: 4,
label: "Apply",
// Our button id, we can use that later to identify,
// that the user has clicked this specific button
custom_id: "send_application"
}
]
}
]
}
});
}
});
你只需要用一行来修改你的代码。 您只需通过 Discord API 帖子发送您的exampleEmbed
,而不是使用discord.js
方法。
为此,您所要做的就是添加一个embeds
字段,该字段接受一个embed
对象数组,您已方便地将其标记为exampleEmbed
,并将其放在那里。
像这样:
client.api.channels(message.channel.id).messages.post({
data: {
//adds the embed here, so the button and embed will be sent together
embeds: [exampleEmbed],
components: [
{
type: 1,
components: [
{
type: 2,
style: 1,
label: "Apply",
// Our button id, we can use that later to identify,
// that the user has clicked this specific button
custom_id: "send_application"
}
]
}
],
}
});
这是Discord API 文档供参考。
另外, discord.js
v13好像也支持按键,不过最近才发布,没时间看。
使用 discord.js v14 是可能的。 我认为您在一条消息中最多允许 5 个 actionrow 假设您使用了内置于 discord.js v14 中的 ActionRowBuilder,每个 actionrow 5 个按钮
interaction.reply({content: 'message(optional), embed: [embed] components: [actionRowComponent1.toJSON()]});
interaction.reply 用于斜杠命令,但我认为这也适用于 message.reply
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.