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 = {
      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 367 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 669 days ago