{"id":13410557,"url":"https://github.com/GitSparTV/discordia-slash","last_synced_at":"2025-03-14T16:32:23.483Z","repository":{"id":53172183,"uuid":"323726391","full_name":"GitSparTV/discordia-slash","owner":"GitSparTV","description":"Discordia application commands extension","archived":false,"fork":false,"pushed_at":"2023-11-16T15:55:39.000Z","size":85,"stargazers_count":36,"open_issues_count":4,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-31T20:43:09.108Z","etag":null,"topics":["discord","discordia","lua","luvit"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GitSparTV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-22T20:28:16.000Z","updated_at":"2024-06-11T13:53:41.000Z","dependencies_parsed_at":"2023-11-16T16:51:32.235Z","dependency_job_id":"ab8a2599-9526-4727-9918-6af04a29fd8a","html_url":"https://github.com/GitSparTV/discordia-slash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSparTV%2Fdiscordia-slash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSparTV%2Fdiscordia-slash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSparTV%2Fdiscordia-slash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSparTV%2Fdiscordia-slash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GitSparTV","download_url":"https://codeload.github.com/GitSparTV/discordia-slash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243610249,"owners_count":20318931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discordia","lua","luvit"],"created_at":"2024-07-30T20:01:07.674Z","updated_at":"2025-03-14T16:32:23.149Z","avatar_url":"https://github.com/GitSparTV.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":["Lua"],"readme":"# discordia-slash\n**[Discordia](https://github.com/SinisterRectus/Discordia) 2.0 extension for [slash commands](https://discord.com/developers/docs/interactions/slash-commands).**\n\n---\n\n## WIP docs\n\nDependency: https://github.com/Bilal2453/discordia-interactions\n\nAsk me in Discord: Spar#6665 or [here](https://discord.gg/sinisterware)\n\n\n**This lib is working only with guild commands**\n\n\n```lua\nlocal dia = require(\"discordia\")\nlocal dcmd = require(\"discordia-slash\")\n-- required to initialize:\nlocal CLIENT = dia.Client():useApplicationCommands()\n\n-- for slash commands\n-- ia - interaction from discordia-interactions\n-- cmd - basically ia.data\n-- args - parsed options\nCLIENT:on(\"slashCommand\", function(ia, cmd, args)\n\nend)\n\n-- for message commands\n-- msg - Message object\nCLIENT:on(\"messageCommand\", function(ia, cmd, msg)\n\nend)\n\n-- for user commands\n-- msg - Member object\nCLIENT:on(\"userCommand\", function(ia, cmd, member)\n\nend)\n\n-- for autocompletion\n-- focused_option - option where focused = true\n\n-- cmd.focused returns value directly\nCLIENT:on(\"slashCommandAutocomplete\", function(ia, cmd, focused_option, args)\n\nend)\n```\n\nAn example of a bot that uses slash, user and message commands,\nusing slash commands constructor:\n\n```lua\nlocal dia = require(\"discordia\")\nlocal tools = require(\"discordia-slash\").util.tools()\nlocal CLIENT = dia.Client():useApplicationCommands()\n\nCLIENT:on(\"ready\", function()\n  -- you'll have to load application commands into discord first in order to use them.\n  -- however, after loading once, you don't have to load them everytime your bot loads.\n\n  -- gets a list of registered application commands from discord bot\n  local commands = CLIENT:getGlobalApplicationCommands()\n  -- deletes any existing application command from the bot's commands list\n  for commandId in pairs(commands) do\n    CLIENT:deleteGlobalApplicationCommand(commandId)\n  end\n\n  local slashCommand = {}\n  local option = {}\n\n  -- creates a slash command constructor\n  slashCommand = tools.slashCommand(\"blep\", \"Send a random adorable animal photo\")\n  -- creates a string option constructor\n  option = tools.string(\"animal\", \"The type of the animal\")\n  -- adds three choices into the option\n  option = option:addChoice(tools.choice(\"Dog\", \"animal_dog\"))\n  option = option:addChoice(tools.choice(\"Cat\", \"animal_cat\"))\n  option = option:addChoice(tools.choice(\"Penguin\", \"animal_penguin\"))\n  -- and sets as a required option\n  option = option:setRequired(true)\n  -- adds option into slash command \"blep\"\n  slashCommand = slashCommand:addOption(option)\n\n  -- creates another string option constructior\n  option = tools.string(\"only_smol\", \"Whether to show only baby animals\")\n  -- adds another option into slash command \"blep\"\n  slashCommand = slashCommand:addOption(option)\n\n  -- creates user command and message command\n  local userCommand = tools.userCommand(\"Get avatar\")\n  local messageCommand = tools.messageCommand(\"Look message\")\n\n  -- register application commands into the bot's commands\n  CLIENT:createGlobalApplicationCommand(slashCommand)\n  CLIENT:createGlobalApplicationCommand(userCommand)\n  CLIENT:createGlobalApplicationCommand(messageCommand)\n\n  CLIENT:info(\"Ready!\");\nend)\n\nCLIENT:on(\"slashCommand\", function(interaction, command, args)\n  if command.name == \"blep\" then\n\n    if args.animal == \"animal_dog\" then\n      interaction:reply(\"You chose a dog!\") -- pass a true value to set the reply ephemeral\n    elseif args.animal == \"animal_cat\" then\n      interaction:reply(interaction.user.name .. \" chose a cat!\")\n    elseif args.animal == \"animal_penguin\" then\n      interaction:reply(\"You chose a penguin!\")\n    end\n\n  end\nend)\n\nCLIENT:on(\"messageCommand\", function(interaction, command, message)\n  if command.name == \"Look message\" then\n    interaction:reply(message.content .. \"\\nhmm yes, this message is made out of message.\", true)\n  end\nend)\n\nCLIENT:on(\"userCommand\", function(interaction, command, member)\n  if command.name == \"Get avatar\" then\n    interaction:reply(member:getAvatarURL(1024), true)\n  end\nend)\n\nCLIENT:run('Bot ' .. bot_token)\n```\n\n### Utils\nUseful constructors and tools. Get by `discordia_slash.util`.\n\n#### tools\n\n##### `string = tools.getSubCommand(cmd)`\nReturns called subcommand as string path.\nFor example slash command `action` has 2 subcommand groups `do` and `undo`. Each one has `ban` and `mute` subcommands.\nWhen user calls `action -\u003e do -\u003e ban` this function returns `do.ban`. This is useful for multilevel commands to lookup the callback faster, instead of doing bunch of if's\n\n##### `tools.userError(ia, err)`\nReplies to the user with error message. Ephemeral.\n\nExample:\n**Interaction Error**\nError message\n\n##### `tools.devError(ia, err, trace)`\nReplies to the user with error message and traceback. Ephemeral.\n\nExample:\n**Interaction Error**\nError message\n```lua\ndebug traceback:\n\tblah\n\t\tblah\n```\n\n##### `tools.argError(ia, arg, comment)`\nReplies to the user with error message about the invalid argument. Ephemeral.\n\nExample:\n**Invalid argument `arg1`**\n\nThe arg is wrong\n\n##### `tools.serializeApplicationCommand(cmd)`\nReturns: `command_name` [CommandType] (command_id)\n\nCommandType is either `Slash Command`, `User Command` or `Message Command`\n\n##### `tools.tryReply(ia, content, ephemeral)`\nTry to call `ia:reply`. If failed print error message\n\n##### `tools.choice(name, value)`\nConstructor for option choice.\nCreates `{name = name, value = value}`\n\n##### `tools.userPermission(user_id, allow_type)`\nConstructor for user permission.\n\n##### `tools.rolePermission(role_id, allow_type)`\nConstructor for role permission.\n\n##### `tools.permission(object, allow_type)`\nConstructor for object permission. Object is either Role or Member class.\n\n#### `CommandConstructor = CommandConstructor:setName(name)`\nSets name\n\nReturns self\n\n#### `CommandConstructor = CommandConstructor:setDescription(description)`\nSets description\n\nReturns self\n\n#### `CommandConstructor = CommandConstructor:addOption(option)`\nAdds option.\n\nReturns self\n\n#### `CommandConstructor = CommandConstructor:setOptions(options)`\nReplaces options with `options`\n\nReturns self\n\n#### `CommandConstructor = CommandConstructor:setType(type)`\nSets application command type\n\nReturns self\n\n#### `CommandConstructor = CommandConstructor:setDefaultPermission(default_permission)`\nSets default permission for the use. (Can @everyone use it?)\n\nReturns self\n\n##### `CommandConstructor = tools.applicationCommand()`\nEmpty application command constructor\n\n##### `CommandConstructor = tools.slashCommand(name, description)`\nSlash command constructor\n\n##### `CommandConstructor = tools.userCommand(name)`\nUser command constructor\n\n##### `CommandConstructor = tools.messageCommand(name)`\nMessage command constructor\n\n#### `OptionConstructor = OptionConstructor:setName(name)`\nSets name\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setDescription(description)`\nSets description\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setType(type)`\nSets option type\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:addOption(option)`\nAdds option.\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setOptions(options)`\nReplaces options with `options`\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setRequired(required)`\nSet required flag on the option\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:addChoice(choice)`\nAdds choice to the option\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setChoices(choices)`\nReplaces choices with `choices`\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:addChannelType(channel_type)`\nAdds channel type to `channel_types` filter\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setChannelTypes(channel_types)`\nReplace channel_types with `channel_types`\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setMinValue(min_value)`\nSets minimum value for the option\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setMaxValue(max_value)`\nSets maximum value for the option\n\nReturns self\n\n#### `OptionConstructor = OptionConstructor:setAutocomplete(autocomplete)`\nSets autocomplete flag on the option\n\nReturns self\n\n##### `tools.option()`\nEmpty option constructor\n\n##### `tools.subCommand(name, description)`\nSubcommand option constructor\n\n##### `tools.subCommandGroup(name, description)`\nSubcommand group option constructor\n\n##### `tools.string(name, description)`\nString option constructor\n\n##### `tools.integer(name, description)`\nInteger option constructor\n\n##### `tools.boolean(name, description)`\nBoolean option constructor\n\n##### `tools.user(name, description)`\nUser option constructor\n\n##### `tools.channel(name, description)`\nChannel option constructor\n\n##### `tools.role(name, description)`\nRole option constructor\n\n##### `tools.mentionable(name, description)`\nMentionable option constructor\n\n##### `tools.number(name, description)`\nNumber option constructor\n\n##### `tools.attachment(name, description)`\nAttachment option constructor\n\n#### appcmd\nALlows you to add and edit commands without code.\n\nTo add appcmd to your guild call before `CLIENT:on(\"ready\")`:\n```lua\ndcmd.util.appcmd(CLIENT, \"ID of your guild\")\n```\n\nThis will add appcmd command, only the owner of the bot can use it by default.\n\n```markdown\n*Utility to edit application commands from discord*\nAllowed for everyone: **disallowed**\n│\n├─ `create` (Subcommand) – *Create new command*\n│     ├─ `name` (String) – *Command name* [required]\n│     ├─ `description` (String) – *Command desciption (will be ignored for non slash commands types)* [required]\n│     ├─ `type` (Integer) – *Command type (Slash command by default)* [choices:3]\n│     └─ `default_permission` (Boolean) – *Command default permission (true by default)*\n├─ `delete` (Subcommand) – *Delete command*\n│     └─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n├─ `get` (Subcommand) – *Get all commands or information about specific command*\n│     └─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n├─ `code` (Subcommand) – *Get command code*\n│     └─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n├─ `edit` (Subcommand) – *Edit first-level fields*\n│     ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n│     ├─ `name` (String) – *Command name*\n│     ├─ `description` (String) – *Command description (slash commands only)*\n│     └─ `default_permission` (Boolean) – *Command default permission (true by default)*\n├─ `permissions` (Subcommand Group) – *Edit command permissions*\n│     ├─ `get` (Subcommand) – *See permissions of all commands or specific one*\n│     │     └─ `id` (String) – *ApplicationCommand ID* [autocomplete]\n│     └─ `set` (Subcommand) – *Set permission for a command*\n│           ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n│           ├─ `what` (Mentionable) – *What should have different permission* [required]\n│           └─ `value` (Integer) – *Value to set* [required, choices:3]\n└─ `option` (Subcommand Group) – *Option related category*\n      ├─ `create` (Subcommand) – *Create option*\n      │     ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n      │     ├─ `type` (Integer) – *Option type* [required, choices:11]\n      │     ├─ `name` (String) – *Option name* [required]\n      │     ├─ `description` (String) – *Option description* [required]\n      │     ├─ `where` (String) – *Place to insert (example: option.create) (root level by default)*\n      │     ├─ `required` (Boolean) – *Is option required? (false by default)*\n      │     ├─ `min_value` (Number) – *Minimum value for the option (Only for integer and number types)*\n      │     ├─ `max_value` (Number) – *Maximum value for the option (Only for integer and number types)*\n      │     ├─ `autocomplete` (Boolean) – *Autocompletion feature (only for string, integer and number types, false by default)*\n      │     ├─ `channel_types` (Integer) – *Channel types allowed to pick (Only for channel type)* [choices:8]\n      │     └─ `replace` (Boolean) – *Replace existing option*\n      ├─ `edit` (Subcommand) – *Edit option*\n      │     ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n      │     ├─ `what` (String) – *Option name* [required]\n      │     ├─ `where` (String) – *Place to insert (example: option.create) (root level by default)*\n      │     ├─ `type` (Integer) – *Option type* [choices:11]\n      │     ├─ `name` (String) – *Option name*\n      │     ├─ `description` (String) – *Option description*\n      │     ├─ `required` (Boolean) – *Is option required? (false by default)*\n      │     ├─ `min_value` (Number) – *Minimum value for the option (Only for integer and number types)*\n      │     ├─ `max_value` (Number) – *Maximum value for the option (Only for integer and number types)*\n      │     ├─ `autocomplete` (Boolean) – *Autocompletion feature (only for string, integer and number types, false by default)*\n      │     └─ `channel_types` (String) – *Channel types allowed to pick separated by space (Only for channel type)*\n      ├─ `delete` (Subcommand) – *Delete option*\n      │     ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n      │     ├─ `what` (String) – *Option name* [required]\n      │     └─ `where` (String) – *Place where the option is (example: option.create) (root level by default)*\n      ├─ `move` (Subcommand) – *Move option*\n      │     ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n      │     ├─ `what` (String) – *Option name* [required]\n      │     ├─ `place` (Integer) – *Order* [required, min_value:1]\n      │     └─ `where` (String) – *Place where the option is (example: option.create) (root level by default)*\n      └─ `choice` (Subcommand) – *Add choice to option*\n            ├─ `id` (String) – *ApplicationCommand ID* [required, autocomplete]\n            ├─ `what` (String) – *Option name* [required]\n            ├─ `choice_name` (String) – *Choice visible name* [required]\n            ├─ `choice_value` (String) – *Choice value* [required]\n            └─ `where` (String) – *Place where the option is (example: option.create) (root level by default)*\n```\n\n#### test\nAllow you to test all slash discordia features.\n\nTo add test to your guild call before `CLIENT:on(\"ready\")`:\n```lua\ndcmd.util.test(CLIENT, \"ID of your guild\")\n```\n\n### Exposed Client functions\n```lua\nClient:getGlobalApplicationCommands()\nClient:createGlobalApplicationCommand(id, payload)\nClient:getGlobalApplicationCommand(id)\nClient:editGlobalApplicationCommand(id, payload)\nClient:deleteGlobalApplicationCommand(id)\nClient:getGuildApplicationCommands(guild_id)\nClient:createGuildApplicationCommand(guild_id, id, payload)\nClient:getGuildApplicationCommand(guild_id, id)\nClient:editGuildApplicationCommand(guild_id, id, payload)\nClient:deleteGuildApplicationCommand(guild_id, id)\nClient:getGuildApplicationCommandPermissions(guild_id)\nClient:getApplicationCommandPermissions(guild_id, id)\nClient:editApplicationCommandPermissions(guild_id, id, payload)\nClient:useApplicationCommands()\n```\n\n### Client.\\_api bindings\n\n```lua\nAPI:getGlobalApplicationCommands(application_id)\nAPI:createGlobalApplicationCommand(application_id, payload)\nAPI:getGlobalApplicationCommand(application_id, command_id)\nAPI:editGlobalApplicationCommand(application_id, command_id, payload)\nAPI:deleteGlobalApplicationCommand(application_id, command_id)\nAPI:bulkOverwriteGlobalApplicationCommands(application_id, payload)\nAPI:getGuildApplicationCommands(application_id, guild_id)\nAPI:createGuildApplicationCommand(application_id, guild_id, payload)\nAPI:getGuildApplicationCommand(application_id, guild_id, command_id)\nAPI:editGuildApplicationCommand(application_id, guild_id, command_id, payload)\nAPI:deleteGuildApplicationCommand(application_id, guild_id, command_id)\nAPI:bulkOverwriteGuildApplicationCommands(application_id, guild_id, payload)\nAPI:getGuildApplicationCommandPermissions(application_id, guild_id)\nAPI:getApplicationCommandPermissions(application_id, guild_id, command_id)\nAPI:editApplicationCommandPermissions(application_id, guild_id, command_id, payload)\nAPI:batchEditApplicationCommandPermissions(application_id, guild_id, payload)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGitSparTV%2Fdiscordia-slash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGitSparTV%2Fdiscordia-slash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGitSparTV%2Fdiscordia-slash/lists"}