From dc8b0cc5afbd012b7f4be060dc5cefe9b3c03947 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Mon, 15 Jun 2020 03:11:07 -0700 Subject: enjoy the essay readme ))) :heart: --- bot.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bot.lua (limited to 'bot.lua') 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 -- cgit v1.2.3