Skip to content

Disgoform is a tool used to manage the application commands of your Discord Bot with code. Terraform for Discord Application Commands.

License

Notifications You must be signed in to change notification settings

switchupcb/disgoform

Repository files navigation

Manage a Discord Bot's Application Commands

GoDoc License

Use disgoform to stop wasting development time sending application command updates to the Discord API.

What is Disgoform?

Disgoform is a tool used to manage the application commands of your Discord Bot.

You run disgoform as a program which imports a Go module to synchronize a Discord Bot's declared application commands with the Discord API.

go get github.com/switchupcb/[email protected]

Table of Contents

Topic Categories
How do you use Disgoform? Define Client, Declare commands, Sync
What else can Disgoform do? Reverse Sync

How do you use Disgoform?

View the main example for the example .go file.

You can download the Go programming language here.

1. Define your client.

Disgoform uses the Discord HTTP REST API to update application commands from a Go program.

bot := &disgo.Client{
    ApplicationID:  "APPID",
    Authentication: disgo.BotToken("TOKEN"), // or BearerToken("TOKEN")
    Config:         disgo.DefaultConfig(),
}

2. Define your application commands.

Read the Discord API Documentation for more information about Application Commands.

TIP: Use a Go: Fill struct macro (e.g., Ctrl . on VSCode) to declare each command faster.

disgoform.GlobalApplicationCommands = []disgo.CreateGlobalApplicationCommand{
    // Command 1
    {
        Name:        "main",
        Description: disgo.Pointer("A basic command."),
        Type:        disgo.Pointer(disgo.FlagApplicationCommandTypeCHAT_INPUT),
    },

    // Command 2
    {
        Name:        "followup",
        Description: disgo.Pointer("Showcase multiple types of interaction responses."),
    },

    // Command 3
    {
        Name:        "autocomplete",
        Description: disgo.Pointer("Learn about autocompletion."),
        Options: []*disgo.ApplicationCommandOption{
            {
                Name:        "freewill",
                Description: "Do you have it?",
                Type:        disgo.FlagApplicationCommandOptionTypeSTRING,
                Required:    disgo.Pointer(true),
                Choices: []*disgo.ApplicationCommandOptionChoice{
                    {
                        Name:  "Yes",
                        Value: "y",
                    },
                    {
                        Name:  "No",
                        Value: "n",
                    },
                },
            },
            {
                Name:         "confirm",
                Description:  "Confirm your answer.",
                Type:         disgo.FlagApplicationCommandOptionTypeSTRING,
                Required:     disgo.Pointer(true),
                Autocomplete: disgo.Pointer(true),
            },
        },
    },

    // Command...
    {
        NameLocalizations:        &map[string]string{},
        Description:              nil,
        DescriptionLocalizations: &map[string]string{},
        DefaultMemberPermissions: nil,
        Type:                     nil,
        NSFW:                     nil,
        Name:                     "",
        Options:                  []*disgo.ApplicationCommandOption{},
        IntegrationTypes:         []disgo.Flag{},
        Contexts:                 []disgo.Flag{},
    },
}

Define Guild Application Commands using the same format.

disgoform.GuildApplicationCommands = []disgo.CreateGuildApplicationCommand{
    // Command...
    {
        NameLocalizations:        &map[string]string{},
	Description:              nil,
	DescriptionLocalizations: &map[string]string{},
	DefaultMemberPermissions: nil,
	Type:                     nil,
	NSFW:                     nil,
	GuildID:                  "",
	Name:                     "",
	Options:                  []*disgo.ApplicationCommandOption{},
    },
}

NOTE: The commands in this example are sourced from Disgo examples.

3. Synchronize your application commands.

Synchronize the Discord Bot's defined application commands with the Discord API.

// Use disgoform.Sync to synchronize Global and Guild application commands.
//
// Use disgoform.SyncGlobalApplicationCommands to only synchronize global application commands.
// Use disgoform.SyncGuildApplicationCommands to only synchronize guild application commands.
if err := disgoform.Sync(bot); err != nil {
    log.Printf("can't synchronize application commands with Discord: %v", err)
}

Use go build -o disgoform to build the executable binary, then run disgoform from the command line.

> disgoform
Synchronizing Global Application Commands...
Synchronized Global Application Commands.
Synchronizing Guild Application Commands...
Synchronized Guild Application Commands.

What else can Disgoform do?

You can also generate a disgoform config.go file using disgoform.SyncConfig.

Here is an example.

bot := &disgo.Client{
    ApplicationID:  "APPID",
    Authentication: disgo.BotToken("TOKEN"), // or BearerToken("TOKEN")
    Config:         disgo.DefaultConfig(),
}

guildIDs := []string{"...", "...", "..."}

// Use disgoform.SyncConfig to output a synchronization file from the Discord Bot's current state.
output, err := disgoform.SyncConfig(bot, guildIDs)
if err != nil {
    log.Printf("can't output Discord application command configuration file: %v", err)

    return
}

fmt.Println(output)

Use go build -o config to build the executable binary, then run it from the command line and redirect the output to a file.

config > config.go

You can implement this unimplemented feature by contributing.

About

Disgoform is a tool used to manage the application commands of your Discord Bot with code. Terraform for Discord Application Commands.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages