Discordia 2.0 extension for slash commands.
Dependency: https://github.com/Bilal2453/discordia-interactions
Ask me in Discord: Spar#6665 or here
This lib is working only with guild commands
local dia = require("discordia")
local dcmd = require("discordia-commands")
-- required to initialize:
local CLIENT = dia.Client():useApplicationCommands()
-- for slash commands
-- ia - interaction from discordia-interactions
-- cmd - basically ia.data
-- args - parsed options
CLIENT:on("slashCommand", function(ia, cmd, args)
end)
-- for message commands
-- msg - Message object
CLIENT:on("messageCommand", function(ia, cmd, msg)
end)
-- for user commands
-- msg - Member object
CLIENT:on("userCommand", function(ia, cmd, member)
end)
-- for autocompletion
-- focused_option - option where focused = true
-- cmd.focused returns value directly
CLIENT:on("slashCommandAutocomplete", function(ia, cmd, focused_option, args)
end)
Useful constructors and tools. Get by discordia_slash.util
.
Returns called subcommand as string path.
For example slash command action
has 2 subcommand groups do
and undo
. Each one has ban
and mute
subcommands.
When user calls action -> do -> ban
this function returns do.ban
. This is useful for multilevel commands to lookup the callback faster, instead of doing bunch of if's
Replies to the user with error message. Ephemeral.
Example: Interaction Error Error message
Replies to the user with error message and traceback. Ephemeral.
Example: Interaction Error Error message
debug traceback:
blah
blah
Replies to the user with error message about the invalid argument. Ephemeral.
Example:
Invalid argument arg1
The arg is wrong
Returns: command_name
[CommandType] (command_id)
CommandType is either Slash Command
, User Command
or Message Command
Try to call ia:reply
. If failed print error message
Constructor for option choice.
Creates {name = name, value = value}
Constructor for user permission.
Constructor for role permission.
Constructor for object permission. Object is either Role or Member class.
Sets name
Returns self
Sets description
Returns self
Adds option.
Returns self
Replaces options with options
Returns self
Sets application command type
Returns self
Sets default permission for the use. (Can @everyone use it?)
Returns self
Empty application command constructor
Slash command constructor
User command constructor
Message command constructor
Sets name
Returns self
Sets description
Returns self
Sets option type
Returns self
Adds option.
Returns self
Replaces options with options
Returns self
Set required flag on the option
Returns self
Adds choice to the option
Returns self
Replaces choices with choices
Returns self
Adds channel type to channel_types
filter
Returns self
Replace channel_types with channel_types
Returns self
Sets minimum value for the option
Returns self
Sets maximum value for the option
Returns self
Sets autocomplete flag on the option
Returns self
Empty option constructor
Subcommand option constructor
Subcommand group option constructor
String option constructor
Integer option constructor
Boolean option constructor
User option constructor
Channel option constructor
Role option constructor
Mentionable option constructor
Number option constructor
Attachment option constructor
ALlows you to add and edit commands without code.
To add appcmd to your guild call before CLIENT:on("ready")
:
dcmd.util.appcmd(CLIENT, "ID of your guild")
This will add appcmd command, only the owner of the bot can use it by default.
*Utility to edit application commands from discord*
Allowed for everyone: **disallowed**
│
├─ `create` (Subcommand) – *Create new command*
│ ├─ `name` (String) – *Command name* [required]
│ ├─ `description` (String) – *Command desciption (will be ignored for non slash commands types)* [required]
│ ├─ `type` (Integer) – *Command type (Slash command by default)* [choices:3]
│ └─ `default_permission` (Boolean) – *Command default permission (true by default)*
├─ `delete` (Subcommand) – *Delete command*
│ └─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
├─ `get` (Subcommand) – *Get all commands or information about specific command*
│ └─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
├─ `code` (Subcommand) – *Get command code*
│ └─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
├─ `edit` (Subcommand) – *Edit first-level fields*
│ ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
│ ├─ `name` (String) – *Command name*
│ ├─ `description` (String) – *Command description (slash commands only)*
│ └─ `default_permission` (Boolean) – *Command default permission (true by default)*
├─ `permissions` (Subcommand Group) – *Edit command permissions*
│ ├─ `get` (Subcommand) – *See permissions of all commands or specific one*
│ │ └─ `id` (String) – *ApplicationCommand ID* [autocomplete]
│ └─ `set` (Subcommand) – *Set permission for a command*
│ ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
│ ├─ `what` (Mentionable) – *What should have different permission* [required]
│ └─ `value` (Integer) – *Value to set* [required, choices:3]
└─ `option` (Subcommand Group) – *Option related category*
├─ `create` (Subcommand) – *Create option*
│ ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
│ ├─ `type` (Integer) – *Option type* [required, choices:11]
│ ├─ `name` (String) – *Option name* [required]
│ ├─ `description` (String) – *Option description* [required]
│ ├─ `where` (String) – *Place to insert (example: option.create) (root level by default)*
│ ├─ `required` (Boolean) – *Is option required? (false by default)*
│ ├─ `min_value` (Number) – *Minimum value for the option (Only for integer and number types)*
│ ├─ `max_value` (Number) – *Maximum value for the option (Only for integer and number types)*
│ ├─ `autocomplete` (Boolean) – *Autocompletion feature (only for string, integer and number types, false by default)*
│ ├─ `channel_types` (Integer) – *Channel types allowed to pick (Only for channel type)* [choices:8]
│ └─ `replace` (Boolean) – *Replace existing option*
├─ `edit` (Subcommand) – *Edit option*
│ ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
│ ├─ `what` (String) – *Option name* [required]
│ ├─ `where` (String) – *Place to insert (example: option.create) (root level by default)*
│ ├─ `type` (Integer) – *Option type* [choices:11]
│ ├─ `name` (String) – *Option name*
│ ├─ `description` (String) – *Option description*
│ ├─ `required` (Boolean) – *Is option required? (false by default)*
│ ├─ `min_value` (Number) – *Minimum value for the option (Only for integer and number types)*
│ ├─ `max_value` (Number) – *Maximum value for the option (Only for integer and number types)*
│ ├─ `autocomplete` (Boolean) – *Autocompletion feature (only for string, integer and number types, false by default)*
│ └─ `channel_types` (String) – *Channel types allowed to pick separated by space (Only for channel type)*
├─ `delete` (Subcommand) – *Delete option*
│ ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
│ ├─ `what` (String) – *Option name* [required]
│ └─ `where` (String) – *Place where the option is (example: option.create) (root level by default)*
├─ `move` (Subcommand) – *Move option*
│ ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
│ ├─ `what` (String) – *Option name* [required]
│ ├─ `place` (Integer) – *Order* [required, min_value:1]
│ └─ `where` (String) – *Place where the option is (example: option.create) (root level by default)*
└─ `choice` (Subcommand) – *Add choice to option*
├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]
├─ `what` (String) – *Option name* [required]
├─ `choice_name` (String) – *Choice visible name* [required]
├─ `choice_value` (String) – *Choice value* [required]
└─ `where` (String) – *Place where the option is (example: option.create) (root level by default)*
Allow you to test all slash discordia features.
To add test to your guild call before CLIENT:on("ready")
:
dcmd.util.test(CLIENT, "ID of your guild")
Client:getGuildApplicationCommands(guild_id)
Client:createGuildApplicationCommand(guild_id, id, payload)
Client:getGuildApplicationCommand(guild_id, id)
Client:editGuildApplicationCommand(guild_id, id, payload)
Client:deleteGuildApplicationCommand(guild_id, id)
Client:getGuildApplicationCommandPermissions(guild_id)
Client:getApplicationCommandPermissions(guild_id, id)
Client:editApplicationCommandPermissions(guild_id, id, payload)
Client:useApplicationCommands()
API:getGlobalApplicationCommands(application_id)
API:createGlobalApplicationCommand(application_id, payload)
API:getGlobalApplicationCommand(application_id, command_id)
API:editGlobalApplicationCommand(application_id, command_id, payload)
API:deleteGlobalApplicationCommand(application_id, command_id)
API:bulkOverwriteGlobalApplicationCommands(application_id, payload)
API:getGuildApplicationCommands(application_id, guild_id)
API:createGuildApplicationCommand(application_id, guild_id, payload)
API:getGuildApplicationCommand(application_id, guild_id, command_id)
API:editGuildApplicationCommand(application_id, guild_id, command_id, payload)
API:deleteGuildApplicationCommand(application_id, guild_id, command_id)
API:bulkOverwriteGuildApplicationCommands(application_id, guild_id, payload)
API:getGuildApplicationCommandPermissions(application_id, guild_id)
API:getApplicationCommandPermissions(application_id, guild_id, command_id)
API:editApplicationCommandPermissions(application_id, guild_id, command_id, payload)
API:batchEditApplicationCommandPermissions(application_id, guild_id, payload)