So when i just use require(filename) it doesn't work, i mean if i use require("filename"), it thinks it's a module so can't open it, it only works if i use require("./filename.lua"), but then it doesn't get me any data from file i require. i can futher provide more details about file containing and other stuff, but that is what i need. my main file:
local dia = require("discordia")
local tools = require("discordia-slash").util.tools()
local CLIENT = dia.Client():useApplicationCommands()
local mycommands = require('./cstmcommands.lua')
i have in CLIENT:on() print(Commands) which is the array that has function in it in cstmcommands.lua, but it prints nil. I tried printing other things from cstmcommands.lua, but it prints nil always.
Provide some informations, guides, tutorials, or answer the question straight how to solve this problem with require when even when i do require() it doesn't get data from file in Discordia core which is written on luvit.
terminal output
C:\Unnesessary\Smallbot on Lua>luvit ./main
2023-09-03 21:35:01 | [INFO] | Discordia 2.11.2
2023-09-03 21:35:01 | [INFO] | Connecting to Discord...
2023-09-03 21:35:02 | [INFO] | Authenticated as (botname)
2023-09-03 21:35:02 | [INFO] | Launching shard 0 (1 out of 1)...
2023-09-03 21:35:02 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2023-09-03 21:35:02 | [INFO] | Shard 0 : Received HELLO
2023-09-03 21:35:02 | [INFO] | Shard 0 : Received READY
Uncaught Error: C:\Unnesessary\Smallbot on Lua\main.lua:26: attempt to index global 'Commands' (a nil value)
stack traceback:
C:\Unnesessary\Smallbot on Lua\main.lua: in function <C:\Unnesessary\Smallbot on Lua\main.lua:7>
stack traceback:
[C]: in function 'error'
C:/Unnesessary/Smallbot on Lua/deps/coro-channel.lua:16: in function 'assertResume'
C:/Unnesessary/Smallbot on Lua/deps/coro-channel.lua:69: in function 'onPlain'
...nesessary/Smallbot on Lua/deps/secure-socket/biowrap.lua:76: in function <...nesessary/Smallbot on Lua/deps/secure-socket/biowrap.lua:61>
[C]: in function 'run'
[string "bundle:/init.lua"]:55: in function <[string "bundle:/init.lua"]:47>
[C]: in function 'xpcall'
[string "bundle:/init.lua"]:47: in function 'fn'
[string "bundle:deps/require.lua"]:310: in function <[string "bundle:deps/require.lua"]:266>
C:\Unnesessary\Smallbot on Lua>pause
cstmcommands content
Commands = {}
Cmd = {
["вітання"] = {
name = "вітання",
description = "Надішли вітання боту, або обраному користувачу",
options = {
{
name = "користувач",
description = "Обери користувача, якому бот надішле повідомлення",
type = "user",
required = false,
choises = nil
}
}
}
}
function Commands:apply()
entered_commands = {}
for group, optcmd in pairs(Cmd) do
for _, v in pairs(optcmd) do
local SlashCommand = {}
local option = {}
for i, v in pairs(optcmd.options) do
n = i
local optiontype = v.type
option = {tools.optiontype(optcmd.options.v.name, optcmd.options.v.description)}
end
SlashCommand = tools.slashCommand(optcmd.name, optcmd.description)
local n = 0
for i = 1, n, 1 do
SlashCommand = SlashCommand:addOption(option[i])
end
entered_commands[group] = SlashCommand
end
end
return entered_commands
end
i found answer, here how to use require() in Discordia if you have a command, use path to it from file you are requiring in
local Commands = require("./name of your file.lua")if you have many of commands require them tooand then go to your file, and use return function like that
remember to do it in your file, then you can print things from Commands if you need to return many values, use
now you know how to require and can make some projects with it, but remember, file can't translate things to each other if only in one used require, so if you have values in 1st file and require it in 2nd, but you have values of 2nd in 1st, you have to identify them or require 2nd in 1st, like that: 1st file:
2nd: