So this question is a complicated one, but i'll try to explain it as much understandable as possible. I am using Discordia to make a discord bot and Discordia-slash to apply a slash-commands ("/"). Then i desided to make 2 separated files, one with commands list and applying them and one with all other bot thing, and i made this
local discordia = require('discordia')
local tools = require('discordia-slash').util.tools()
Commands = {}
function Commands.apply()
local SlashCommand = {}
for group, commanddata in pairs(Cmd) do
table.insert(SlashCommand, {
name = commanddata["назва"],
description = commanddata["опис"],
type = 1,
})
if commanddata["опції"] then
for numeric, optiondata in pairs(commanddata["опції"]) do
for command, value in pairs(SlashCommand) do
SlashCommand[command].options = {
name = optiondata["назва"],
description = optiondata["опис"],
type = optiondata["тип"]
}
end
end
end
end
for i, v in pairs(SlashCommand) do
for i2, v2 in pairs(v) do
print(i, i2, v2)
end
return SlashCommand[i]
end
end
return Commands
That function makes a ready to use Commands list like
SlashCommand = {
{
name = ...,
description = ...,
options = {...}
},
{
name = ...,
description = ...,
}
and i have this in my main file:
CLIENT:on("ready", function()
-- you'll have to load application commands into discord first in order to use them.
-- however, after loading once, you don't have to load them everytime your bot loads.
-- gets a list of registered application commands from discord bot
local commands = CLIENT:getGlobalApplicationCommands()
-- deletes any existing application command from the bot's commands list
for commandId in pairs(commands) do
CLIENT:deleteGlobalApplicationCommand(commandId)
end
-- register application commands into the bot's commands
CLIENT:info("готово до використання")
print("Активовано: ".. CLIENT.user.tag)
end)
and my Commands.apply() function should return commands from it's SlashCommand list in row, to apply them all. How to do that, because it's not working with return.