You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB
Lua

local discordia = require('discordia')
local client = discordia.Client()
discordia.extensions() -- load all helpful extensions
local prefix = "."
local commands = {
[prefix .. "ping"] = {
description = "Answers with pong.",
exec = function(message)
message.channel:send("Pong!")
end
},
[prefix .. "hello"] = {
description = "Answers with world.",
exec = function(message)
message.channel:send("world!")
end
}
}
client:on('ready', function()
p(string.format('Logged in as %s', client.user.username))
end)
client:on("messageCreate", function(message)
local args = message.content:split(" ") -- split all arguments into a table
local command = commands[args[1]]
if command then -- ping or hello
command.exec(message) -- execute the command
end
if args[1] == prefix.."help" then -- display all the commands
local output = {}
for word, tbl in pairs(commands) do
table.insert(output, "Command: " .. word .. "\nDescription: " .. tbl.description)
end
message:reply(table.concat(output, "\n\n"))
end
end)
client:run("Bot BOT_TOKEN") -- replace BOT_TOKEN with your bot token