Send message to channel using webhook

Send a text message to a channel given a webhook and a channel ID

Script discord

by admin ยท 8/4/2022

  • Submitted by admin Deno
    Created 1373 days ago
    1
    import type { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    export async function main(
    4
      webhook: Resource<"discord_webhook">,
    5
      content: string,
    6
    ) {
    7
      const req = await fetch(webhook, {
    8
        method: "POST",
    9
        headers: { "Content-type": "application/json" },
    10
        body: JSON.stringify({ content }),
    11
      });
    12
    
    
    13
      if (req.status != 200) {
    14
        throw Error();
    15
      }
    16
    }
    17