Discordia-slash
This section demonstrates how the ‘sticky_navigation’ setting behaves when the menu is very long. When this section is selected, it will make the menu and the main area scroll when you are at the top of the page.
Installation
First off, you need to install the deps
$ git clone https://github.com/Bilal2453/discordia-interactions ./deps/discordia-interactions && git clone https://github.com/GitSparTV/discordia-slash ./deps/discordia-slash
Examples
Slash commands
Import the discordia-slash
local discordia= require("discordia")
local dcmd = require("discordia-slash")
Create a slash command
local client = discordia.Client():useApplicationCommands()
local function initializeCommands(guild)
local command, err = client:createGuildApplicationCommand(guild.id, {
name = "test",
description = " nice",
options = {
{
type = optionType.subCommand,
name = " from",
description = "Enter the id",
options = {
{
type = optionType.string, --putting .user will make the person select a user and not just input a string
name = "person",
description = "id",
required = true,
autocomplete = true,
},
},
},
},
})
end
client:on("ready", function()
for guild in client.guilds:iter() do
initializeCommands(guild) --there are other way to initialize it but it is the only way i know
end
end)
What this will do is that it will create a slash command with a text input and the client:on(“ready”) will initialize the command onto the server, note that there are other way to initialize the command but i use that one.
Get the data from the text input
client:on("slashCommand", function(interaction, command, args)
print(args.from.person)
end)
This will print out the value that has been put in the text field from the slash command The reason why it has a .from. is because there is the from subcomand between the value and the command, and the name of the value would be person as the name in the example above says.
Full code
local discordia= require("discordia")
local dcmd = require("discordia-slash")
local client = discordia.Client():useApplicationCommands()
local interactionType = discordia.enums.interactionType
local optionType = discordia.enums.appCommandOptionType
local function initializeCommands(guild)
local command, err = client:createGuildApplicationCommand(guild.id, {
name = "test",
description = " nice",
options = {
{
type = optionType.subCommand,
name = "from",
description = "Enter the id",
options = {
{
type = optionType.string,
name = "person",
description = "id",
required = true, --put false if you want it to be optional
autocomplete = true, --won't change anything if the optionType is a .string, will autocomplete with users if it is a optionType.user
},
},
},
},
})
end
client:on("ready", function()
for guild in client.guilds:iter() do
initializeCommands(guild)
end
end)
client:on("slashCommand", function(interaction, command, args)
print(args.from.person)
interaction:reply("Success!")
end)
client:run("Bot your token")
This will create a slash command, will print the inputed value when running the slash command and reply to the interaction.
App commands
Note
User commands are very similar to slash commands, as they are bundled in the same extension, no need to download the deps if you already have slash commands setup Message commands are also possible but aren’t documented here.
Installation
You need to install those
$ cd deps && git clone https://github.com/GitSparTV/discordia-slash && git clone https://github.com/Bilal2453/discordia-interactions
Import the discordia-slash
local discordia= require("discordia")
local dcmd = require("discordia-slash")
Create a user command
local client = discordia.Client:useApplicationCommands()
local function initializeCommands(guild)
local command, err = client:createGuildApplicationCommand(guild.id, {
type = dia.enums.appCommandType.user, --putting .message could create a message app instead of a user app, but i haven't tested it
name = "role",
})
end
client:on("ready", function()
for guild in client.guilds:iter() do
initializeCommands(guild)
end
end)
It is pretty much the same as slash commands but you can’t put a description, will break otherwise
Get data
client:on("userCommand", function(interaction, command, args)
print(args)
end)
So here since it is a user command, no one can really input data so args would be the user it was used on
Full code
local discordia= require("discordia")
local dcmd = require("discordia-slash")
local client = discordia.Client:useApplicationCommands()
local interactionType = discordia.enums.interactionType
local optionType = discordia.enums.appCommandOptionType
local function initializeCommands(guild)
local command, err = client:createGuildApplicationCommand(guild.id, {
type = dia.enums.appCommandType.user, --putting .message could create a message app instead of a user app, but i haven't tested it
name = "role",
})
end
client:on("ready", function()
for guild in client.guilds:iter() do
initializeCommands(guild)
end
end)
client:on("userCommand", function(interaction, command, args)
print(args)
end)
client:run("Bot your token")