Edits history of script submission #8861 for ' Send message to Discord channel using Discord Bot (discord)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    type DiscordBotConfiguration = {
      // Bot token, sent as `Authorization: Bot <token>`. Preferred field.
      bot_token?: string,
      // Ed25519 key for verifying interactions. Legacy: older resources stored the
      // bot token here, so we fall back to it for backward compatibility.
      public_key?: string,
      application_id: string
    };
    
    // Note: you can also send messages to channels using Discord webhooks: https://hub.windmill.dev/scripts/discord/1288/
    
    import { RequestInit } from 'node-fetch';
    
    export async function main(
      config: DiscordBotConfiguration,
      channelId: string,
      message: string
    ): Promise<any> {
      const url = `https://discord.com/api/v9/channels/${channelId}/messages`;
    
      const payload = {
        content: message
      };
    
      const requestOptions: RequestInit = {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bot ${config.bot_token ?? config.public_key}`
        },
        body: JSON.stringify(payload)
      };
    
      const response = await fetch(url, requestOptions);
    
      return await response.json();
    }

    Submitted by hugo989 8 days ago

  • bun
    type DiscordBotConfiguration = {
      public_key: string,
      application_id: string
    };
    
    // Note: you can also send messages to channels using Discord webhooks: https://hub.windmill.dev/scripts/discord/1288/
    
    import { RequestInit } from 'node-fetch';
    
    export async function main(
      config: DiscordBotConfiguration,
      channelId: string,
      message: string
    ): Promise<any> {
      const url = `https://discord.com/api/v9/channels/${channelId}/messages`;
    
      const payload = {
        content: message
      };
    
      const requestOptions: RequestInit = {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bot ${config.public_key}`
        },
        body: JSON.stringify(payload)
      };
    
      const response = await fetch(url, requestOptions);
    
      return await response.json();
    }

    Submitted by hugo697 399 days ago

  • bun
    type DiscordBotConfiguration = {
      public_key: string,
      application_id: string
    };
    
    // Note: you can also send messages to channels using Discord webhooks: https://hub.windmill.dev/scripts/discord/1288/
    
    import { RequestInit } from 'node-fetch';
    
    export async function main(
      config: DiscordBotConfiguration,
      channelId: string,
      message: string
    ): Promise<any> {
      const url = `https://discord.com/api/v9/channels/${channelId}/messages`;
    
      const payload = {
        content: message
      };
    
      const requestOptions: RequestInit = {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bot ${config.public_key}`
        },
        body: JSON.stringify(payload)
      };
    
      const response = await fetch(url, requestOptions);
    
      return await response.json();
    }

    Submitted by henri186 700 days ago