cmd.message.edit.buttons

Warning

cmd.message.edit.buttons has not been updated in a while and may be considered outdated. It may still work, but could change in future versions.

Edits one or more buttons on an existing message without replacing the entire component layout. Only the fields you provide for each button are changed; everything else stays as-is.

This function is available as a sub-method of cmd.message.edit:

JavaScript
const { cmd } = require("syntx.js");

await cmd.message.edit.buttons(buttonsData, message);

Parameters

ParameterTypeRequiredDescription
buttonsDataobject[]YesArray of button update objects. Must contain at least one entry.
messagediscord.js Message | InteractionYesThe message or interaction that contains the target message.

Each entry in buttonsData identifies a button by its customId and overrides only the specified fields:

FieldTypeRequiredDescription
idstringYesThe customId of the button to update.
labelstringNoNew label text for the button.
stylenumberNoNew button style. Use discord.js ButtonStyle values.
disabledbooleanNoWhether to enable or disable the button.
emojistringNoNew emoji for the button.

Returns

This function does not return a value.

Examples

Disable a button after it is clicked

JavaScript
client.interaction({
  id: "confirm-{userId}",
  content: async (interaction) => {
    await interaction.deferUpdate();

    await cmd.message.edit.buttons(
      [{ id: `confirm-${interaction.user.id}`, disabled: true, label: "Confirmed" }],
      interaction
    );
  },
});

Update multiple buttons at once

JavaScript
client.interaction({
  id: "vote-{option}",
  content: async (interaction) => {
    await interaction.deferUpdate();

    await cmd.message.edit.buttons(
      [
        { id: "vote-yes", label: "Yes (1)", disabled: false },
        { id: "vote-no", label: "No (0)", disabled: false },
      ],
      interaction
    );
  },
});

Note

Buttons are matched by their customId. Any button whose customId does not appear in buttonsData is left unchanged.

Warning

The target message must have existing components. If the message has no buttons, a SyntxError is thrown.