0

Edit message

by
Published Aug 25, 2022
Script discord Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 17 days ago
1
//native
2

3
type DiscordWebhook = {
4
  webhook_url: string;
5
};
6
export async function main(
7
  discord_webhook: DiscordWebhook,
8
  messageId: string,
9
  newMessageContent: string,
10
) {
11
  const response = await fetch(
12
    `${discord_webhook.webhook_url}/messages/${messageId}`,
13
    {
14
      method: "PATCH",
15
      headers: {
16
        "Content-Type": "application/json",
17
      },
18
      body: JSON.stringify({ content: newMessageContent }),
19
    },
20
  );
21
  if (!response.ok) {
22
    throw new Error(`${response.status} ${await response.text()}`);
23
  }
24
  return await response.json();
25
}
26

Other submissions
  • Submitted by lplit Deno
    Created 409 days ago
    1
    import discordwebhook from "https://deno.land/x/discordwebhook/mod.ts";
    2
    
    
    3
    type DiscordWebhook = {
    4
      webhook_url: string;
    5
    };
    6
    export async function main(
    7
      discord_webhook: DiscordWebhook,
    8
      messageId: string,
    9
      newMessageContent: string,
    10
    ) {
    11
      const webhook = new discordwebhook(discord_webhook.webhook_url);
    12
      const ret = await webhook.editMessage(messageId, newMessageContent);
    13
      return ret;
    14
    }
    15