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:
const { cmd } = require("syntx.js");
await cmd.message.edit.buttons(buttonsData, message);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
buttonsData | object[] | Yes | Array of button update objects. Must contain at least one entry. |
message | discord.js Message | Interaction | Yes | The message or interaction that contains the target message. |
Each entry in buttonsData identifies a button by its customId and overrides only the specified fields:
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The customId of the button to update. |
label | string | No | New label text for the button. |
style | number | No | New button style. Use discord.js ButtonStyle values. |
disabled | boolean | No | Whether to enable or disable the button. |
emoji | string | No | New emoji for the button. |
Returns
This function does not return a value.
Examples
Disable a button after it is clicked
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
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.