This release makes some changes to the syntax for declaring subcommands and command parameters in order to bring it more in line with Discord.py.
Note that the old syntax still works, but moving forward, the new syntax will be the preferred method.
Subcommands
Old syntax:
python
discord.command(options=[
{
"name": "google",
"description": "Search with Google",
"type": CommandOptionType.SUB_COMMAND,
"options": [{
"name": "query",
"description": "Search query",
"type": CommandOptionType.STRING,
"required": True
}]
},
{
"name": "bing",
"description": "Search with Bing",
"type": CommandOptionType.SUB_COMMAND,
"options": [{
"name": "query",
"description": "Search query",
"type": CommandOptionType.STRING,
"required": True
}]
}
])
def search(ctx, subcommand, *, query):
"Search the Internet!"
quoted = urllib.parse.quote_plus(query)
if subcommand == "google":
return f"https://google.com/search?q={quoted}"
if subcommand == "bing":
return f"https://bing.com/search?q={quoted}"
New syntax:
python
comic = discord.command_group("comic")
comic.command()
def xkcd(ctx, number: int):
return f"https://xkcd.com/{number}/"
comic.command()
def homestuck(ctx, number: int):
return f"https://homestuck.com/story/{number}"
Command Parameters
Old syntax:
python
discord.command(options=[{
"name": "channel",
"description": "The channel to show information about",
"type": CommandOptionType.CHANNEL,
"required": True
}])
def channel_info(ctx, channel):
return InteractionResponse("...")
New syntax:
python
discord.command(annotations={"channel": "The channel to show information about"})
def channel_info(ctx, channel: Channel):
return Response(...)
Renaming
Old names are (for now) being kept as aliases.
* `InteractionResponse` -> `Response`
* `InteractionContext` -> `Context`