简体   繁体   English

Discord.js 嵌入按钮

[英]Discord.js Button on Embed

I would like to make this send an embed instead of it saying "If you want to apply, click the button below.", and have the apply button underneath the embed I have read up about some Component array and embed array stuff but I can't seem to get anything working with that If anyone could help me out id appreciate it我想让它发送一个嵌入而不是说“如果你想申请,请单击下面的按钮。”,并在嵌入下方有应用按钮我已经阅读了一些关于组件数组和嵌入数组的东西,但我可以似乎没有任何工作如果有人可以帮助我,我将不胜感激

Two very helpful people have helped me两个非常有帮助的人帮助了我

@Skulaurun Mrusal and @PerplexingParadox @Skulaurun Mrusal@PerplexingParadox

Thank you!谢谢!

在此处输入图像描述

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"
              }
            ]
          }
        ]
      }
    });
  }
});

You only need to modify your code with one line.你只需要用一行来修改你的代码。 You just have to send your exampleEmbed through the Discord API post instead of using the discord.js method.您只需通过 Discord API 帖子发送您的exampleEmbed ,而不是使用discord.js方法。

To do that, all you have to do is add an embeds field, which takes in an array of embed objects, which you have conveniently labeled as exampleEmbed , and put it there.为此,您所要做的就是添加一个embeds字段,该字段接受一个embed对象数组,您已方便地将其标记为exampleEmbed ,并将其放在那里。

Like this:像这样:

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"
                    }
                ]
            }
        ],
    }
});

Here's the Discord API documentation for reference.这是Discord API 文档供参考。


In addition, it seems like discord.js v13 also supports buttons as well, but since it's been released pretty recently, I haven't had time to check it out.另外, discord.js v13好像也支持按键,不过最近才发布,没时间看。

Discord.js Guide Discord.js 指南

with discord.js v14 it is possible.使用 discord.js v14 是可能的。 i think you are allowed up to 5 actionrow's in a single message 5 buttons per actionrow assuming you used the ActionRowBuilder Built into discord.js v14我认为您在一条消息中最多允许 5 个 actionrow 假设您使用了内置于 discord.js v14 中的 ActionRowBuilder,每个 actionrow 5 个按钮

interaction.reply({content: 'message(optional), embed: [embed] components: [actionRowComponent1.toJSON()]});

interaction.reply is for slash commands but I think this also works with message.reply as well interaction.reply 用于斜杠命令,但我认为这也适用于 message.reply

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM