# $editMessage

Edits an existing message sent by the bot, or the message of the button or select menu that was just clicked: replaces its text and, optionally, its embed.

## Syntax

```
$editMessage[channelId;messageId;newContent;(title;description;color;footer)]
```

## Parameters

| Parameter | Description | Required |
|-----------|-------------|:-----------:|
| `channelId` | ID of the channel containing the message. Leave it empty (together with `messageId`) to edit the message of the clicked button or select menu | Yes |
| `messageId` | ID of the message to modify. Leave it empty (together with `channelId`) to edit the message of the clicked button or select menu | Yes |
| `newContent` | New text content of the message (the argument must be present; it can be empty). Maximum 2000 characters. | Yes |
| `title` | Embed title, maximum 256 characters (providing the 4th argument, even empty, replaces the embed) | No |
| `description` | Embed description, maximum 4096 characters | No |
| `color` | Embed color: `#RRGGBB`, `RRGGBB` (hex) or an integer. A value made only of digits is read as a decimal integer. Invalid values raise `Invalid embed color.` | No |
| `footer` | Embed footer text, maximum 2048 characters | No |

## Description

`$editMessage` updates an existing message of a channel and returns an empty string. The text of the message is always replaced by `newContent`. When at least one of the optional embed arguments is present (3 to 7 arguments are accepted), the embed of the message is replaced by one built from them; if all of them are empty the embed is removed. Components are not changed.

When both `channelId` and `messageId` are empty, the command must have been triggered by a button or a select menu: the function then edits the message that holds that component, with no ID to look up. Outside of such an interaction it fails with `Give a channel and message ID outside a button or select menu interaction.`

The edit is performed immediately, on an existing message, and affects neither the pending response nor `$sendMessage[]`. Both IDs must be positive integers (`Invalid Discord ID.` otherwise).

The `messageId` can be obtained via:
- `$sendMessage[text;yes]`, which returns the ID of the sent message
- A stored variable
- The ID of the triggering message (`$messageID`)

## Examples

### Simple edit

```bdfd
$editMessage[$channelID;123456789012345678;Updated content!]
```

### Edit after sending

```bdfd
$var[id;$sendMessage[Original message;yes]]
$editMessage[$channelID;$var[id];Modified message!]
```

### Edit with a new embed

```bdfd
$var[id;$sendMessage[Original message;yes]]
$editMessage[$channelID;$var[id];;Update;The information has changed;#FFA500]
```

### When a button is clicked

```bdfd
$if[$customID==btn_edit]
  $editMessage[$channelID;$messageID;Message edited by interaction]
$endif
```

### Edit the message of the clicked button (no IDs)

```bdfd
$editMessage[;;Vote saved ✅;Poll;You voted "Yes";#57F287;Thank you!]
```

## Notes

- `newContent` always replaces the text of the message, even when it is empty.
- Giving the embed arguments (even empty ones) replaces the original embed; omitting them leaves the embed untouched.
- The combined length of title, description and footer cannot exceed 6000 characters (`Embed text exceeds Discord limits.`).
- Editing a message written by someone else fails with `Only the bot own messages can be edited.`
- A Components V2 message carries neither text nor embed: the call fails with `This message uses Components V2: edit it with $editMessageCV2.` (see `$editMessageCV2`).
- Use `$sendMessage[text;yes]` to retrieve the ID of the message sent.

## Canvas

A canvas rendered with `$attachImage` before `$editMessage` replaces the attachments of the edited message (a live map or health bar that updates in place).
