Skip to content

Configuring Commands

Configuring commands

Creating a command is very similar to creating it in JSON, however, this library will assist you in making sure the outcome is a valid schema for Discord. You should still learn how to build commands by reading the documentation on Discord.

Internally this is powered by pydantic. There are third-party plugins to integrate with your favorite IDEs to enable auto-completion when typing.

Caution

Autocompletion for creating new models under DiscordCommand, CommandChoice, CommandOption, SubcommandOption, CommandTypes on VSCode is broken. (follow the discussion here samuelcolvin/pydantic#650, microsoft/python-language-server#1898). PyCharm appears to work using an external plugin.

Let's get started

# Import
from dispike.creating import DiscordCommand, CommandOption, CommandChoice, CommandTypes

from dispike.creating import (
  DiscordCommand,
  CommandOption,
  CommandChoice,
  CommandTypes
)

These are the models that you will need to get started. Think of models as blueprints.

Info

You can go more advanced by also importing [SubcommandOption], but that's more advanced and is not covered in this tutorial.

Let's create a command. The user will interact with this command such as.

/wave <discord user to send wave to>

This is simple to create. Let's make it.

command_to_be_created = DiscordCommand(
    name="wave" # this is the main command name.,
    description="Send a wave to a nice person! 👋 ",
    options=[
        CommandOption(
            name="person" # this is the attribute assigned to the value passed.,
            description="person to target" # this describes the value to pass,
            required=True,
            type=CommandTypes.USER
        )
    ]
)

That's it, simple to create.

Verify that the CommandOption.name is something you can name in a normal python function.

Let's move to register this command.