summaryrefslogtreecommitdiff
path: root/bot.lua
diff options
context:
space:
mode:
author8cy <[email protected]>2020-06-15 03:11:07 -0700
committer8cy <[email protected]>2020-06-15 03:11:07 -0700
commitdc8b0cc5afbd012b7f4be060dc5cefe9b3c03947 (patch)
treebcb7e56dfda865012d719886865fb7b9d35e534d /bot.lua
parentInitial commit (diff)
downloadlua-discord-bot-example-dc8b0cc5afbd012b7f4be060dc5cefe9b3c03947.tar.xz
lua-discord-bot-example-dc8b0cc5afbd012b7f4be060dc5cefe9b3c03947.zip
enjoy the essay readme )))
:heart:
Diffstat (limited to 'bot.lua')
-rw-r--r--bot.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/bot.lua b/bot.lua
new file mode 100644
index 0000000..4f9a59d
--- /dev/null
+++ b/bot.lua
@@ -0,0 +1,53 @@
+local discordia = require('discordia')
+local client = discordia.Client()
+
+local prefix = "$"
+
+discordia.extensions()
+
+client:on('ready', function()
+ print('Logged in as '.. client.user.username)
+end)
+
+local commands = {
+ [prefix .. "ping"] = {
+ description = "Replies to you with pong.",
+ exec = function(msg)
+ msg:reply("pong!")
+ end
+ },
+ [prefix .. "say"] = {
+ description = "Speak as the bot!",
+ exec = function(msg)
+ local content = msg.content
+ local args = content:split(" ")
+
+ table.remove(args, 1)
+ msg.channel:send(table.concat(args, " "))
+ end
+ }
+}
+
+client:on('messageCreate', function(msg)
+ local content = msg.content
+ local args = content:split(" ")
+ local author = msg.author
+
+ if author == client.user then return end
+
+ local command = commands[args[1]]
+ if command then
+ command.exec(msg)
+ end
+
+ if args[1] == prefix.."help" then
+ local output = {}
+ for word, tbl in pairs(commands) do
+ table.insert(output, "Command: " .. word .. "\nDescription: " .. tbl.description)
+ end
+
+ msg:reply(table.concat(output, "\n\n"))
+ end
+end)
+
+client:run('Bot PUT_TOKEN_HERE') -- Because it might be misleading. When inserting your token, keep the "Bot" part and just replace the PUT_TOKEN_HERE. \ No newline at end of file