logo Private Hub
Discord
Discussions
Windmill
Login
0
Add a command to a Discord bot

https://discord.com/developers/docs/interactions/application-commands#making-a-global-command https://www.windmill.dev/blog/knowledge-base-discord-bot

Created by henri186 731 days ago Viewed 3 times
  • 0
    Submitted by henri186 Deno
    Created 731 days ago
    All edits
    Permalink
    1
    import { SlashCommandBuilder } from "npm:@discordjs/builders@1.6.3";
    2
    
    
    3
    export async function main(
    4
      applicationId: string,
    5
      botToken: string,
    6
      commandName: string = "windmill-help",
    7
      commandDescription: string = "Ask a question about Windmill",
    8
      optionDescription: string = "Ask a question about Windmill"
    9
    ) {
    10
      const command = new SlashCommandBuilder()
    11
        .setName(commandName)
    12
        .setDescription(commandDescription)
    13
        .addStringOption((option) =>
    14
          option.setName("question").setDescription(optionDescription)
    15
        );
    16
    
    
    17
      const url = `https://discord.com/api/v10/applications/${applicationId}/commands`;
    18
    
    
    19
      await fetch(url, {
    20
        method: "POST",
    21
        headers: {
    22
          Authorization: `Bot ${botToken}`,
    23
          "Content-Type": "application/json",
    24
        },
    25
        body: JSON.stringify(command.toJSON()),
    26
      });
    27
    }
    28
    
    
Windmill

© 2025 Windmill Labs, Inc. All rights reserved.