kesha
kesha

Reputation: 47

Discord JS, discord-buttons; How to attach more than 5 buttons to a message?

How to attach more than 5 buttons to a message with discord-buttons, discord.js?

Example

The way I try:

let Buttons = [];
    Buttons[0] = new discordButton.MessageButton().setStyle('gray').setID("0").setLabel(' ');
    Buttons[1] = new discordButton.MessageButton().setStyle('gray').setID("1").setLabel(' ');
    Buttons[2] = new discordButton.MessageButton().setStyle('gray').setID("2").setLabel(' ');

    Buttons[3] = new discordButton.MessageButton().setStyle('gray').setID("3").setLabel(' ');
    Buttons[4] = new discordButton.MessageButton().setStyle('gray').setID("4").setLabel(' ');
    Buttons[5] = new discordButton.MessageButton().setStyle('gray').setID("5").setLabel(' ');
    
    Buttons[6] = new discordButton.MessageButton().setStyle('gray').setID("6").setLabel(' ');
    Buttons[7] = new discordButton.MessageButton().setStyle('gray').setID("7").setLabel(' ');
    Buttons[8] = new discordButton.MessageButton().setStyle('gray').setID("8").setLabel(' ');

msg.channel.send(`⁣...`, { buttons:Buttons });

The error it gets:

DiscordAPIError: Invalid Form Body
components[0].components[5]: The specified component exceeds the maximum width
components[0].components[6]: The specified component exceeds the maximum width
components[0].components[7]: The specified component exceeds the maximum width
components[0].components[8]: The specified component exceeds the maximum width

method: 'post',
  path: '/channels/656858400440975371/messages',
  code: 50035,
  httpStatus: 400
}

Does it have something to do with my bot account?

Upvotes: 1

Views: 15867

Answers (2)

Farhan100
Farhan100

Reputation: 76

You can try doing this:

const msg = await message.channel.send({
      embed: YOUR EMBED HERE,
      components: [
        {
          type: 1,
          components: [Button[0], Button[1], Button[2], Button[3], Button[4]],
        },
        {
          type: 1,
          components: [more, buttons, here, max, 5]
        }
        {
          type: 1,
          components: [you, can, do, 5, times]
        }
      ]
  });

I hope this helped :D

Upvotes: 6

damaredayo
damaredayo

Reputation: 1079

I suggest that you read through or reference the Discord API documentation, here you could find out the following information:

  • Buttons must be sent inside an Action Row
  • An Action Row can contain up to 5 buttons

Reference: https://discord.com/developers/docs/interactions/message-components

Upvotes: 1

Related Questions