cmd.message.edit

Edits an existing message sent by the bot. Supports updating text content, embeds, and component rows, with optional Components V2 support. Only the bot's own messages can be edited.

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

await cmd.message.edit({ data, content, embed, embeds, components, preserveUI, options }, client);

Parameters

ParameterTypeRequiredDescription
dataobjectYesTarget message location. See data fields below.
contentstringNoNew plain text content for the message. Pass null to clear it.
embedobjectNoA syntx.js-style embed object to render. See embed fields below.
embedsobject[]NoArray of additional raw discord.js embed objects.
componentsarrayNoNew component rows to set on the message.
preserveUIbooleanNoIf true, existing components are kept and new ones are appended. Defaults to false.
optionsobjectNoAdditional flags. See options below.
clientERXClientYesThe syntx.js client instance.

Data fields

FieldTypeRequiredDescription
channelstringYesID of the channel containing the message.
messageIDstringYesID of the message to edit.

Embed fields

The embed parameter accepts a syntx.js-style object with the following fields:

FieldTypeDescription
titlestringThe embed title.
titleURLstringURL linked in the title.
descriptionstringThe embed description.
colornumberThe embed color as a decimal integer.
imagestringURL of the embed image.
thumbnailstringURL of the embed thumbnail.
authorstringThe embed author name.
authorIconstringURL of the embed author icon.
authorURLstringURL linked in the author name.
footerstringThe embed footer text.
footerIconstringURL of the embed footer icon.
timestampbooleanIf true, sets the timestamp to the current time.
fieldsobject[]Array of { name, value, inline } field objects.

Options

FieldTypeDefaultDescription
v2booleanfalseForce Components V2 mode for the edited message.

Components V2

When options.v2 is true, or when the target message already has the IsComponentsV2 flag, the edit runs in V2 mode. In this mode, content and embeds cannot be used. Place all content inside Display components instead.

Returns

This function does not return a value.

Examples

Update message text

JavaScript
client.command({
  name: "updatetext",
  content: async (message) => {
    await cmd.message.edit(
      {
        data: {
          channel: message.channel.id,
          messageID: "MESSAGE_ID",
        },
        content: "This message has been updated.",
      },
      client
    );
  },
});

Replace components while keeping existing ones

JavaScript
client.command({
  name: "addbutton",
  content: async (message) => {
    const newRow = new Buttons()
      .addButton({ label: "New", id: "new-btn", style: "primary" })
      .build();

    await cmd.message.edit(
      {
        data: {
          channel: message.channel.id,
          messageID: "MESSAGE_ID",
        },
        components: [newRow],
        preserveUI: true,
      },
      client
    );
  },
});

Edit with a new embed

JavaScript
client.command({
  name: "updateembed",
  content: async (message) => {
    await cmd.message.edit(
      {
        data: {
          channel: message.channel.id,
          messageID: "MESSAGE_ID",
        },
        embed: {
          title: "Updated",
          description: "This embed was edited.",
          color: 0x57f287,
        },
      },
      client
    );
  },
});

Warning

Only messages authored by the bot can be edited. Attempting to edit another user's message will throw a SyntxError. The second argument must be the ERXClient instance, not a message or interaction object.