Repository navigation
Expand file tree
/
Copy pathinteraction_bot.lua
More file actions
67 lines (60 loc) · 1.87 KB
/
Copy pathinteraction_bot.lua
File metadata and controls
67 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- examples/interaction_bot.lua
-- Example: Bot built entirely on slash commands.
--
-- No prefix commands here, just slash_command with typed
-- options. ctx:respond/reply must be called within Discord's 3 second
-- interaction window; ctx:edit can update the response afterward.
local discord = require("discord.lua")
-- Interactions arrive over the same gateway connection, but reading them
-- does not need a privileged intent. GUILDS is enough to cache the guild
-- the interaction came from.
local bot = discord.Bot(discord.enums.INTENTS.GUILDS)
bot:on("ready", function()
print("Bot is ready!")
end)
bot:slash_command("echo", {
description = "Repeats back what you typed",
options = {
{
name = "text",
type = discord.enums.OPTION_TYPE.STRING,
description = "Text to repeat",
required = true,
},
},
callback = function(ctx)
local text = ctx:require_arg("text")
ctx:respond(text)
end,
})
bot:slash_command("roll", {
description = "Rolls a die",
options = {
{
name = "sides",
type = discord.enums.OPTION_TYPE.INTEGER,
description = "Number of sides, defaults to 6",
required = false,
},
},
callback = function(ctx)
local sides = ctx:get_arg("sides", 6)
ctx:respond("Rolled: " .. math.random(1, sides))
end,
})
bot:slash_command("note", {
description = "Sends a private note only you can see",
options = {
{
name = "message",
type = discord.enums.OPTION_TYPE.STRING,
description = "The note content",
required = true,
},
},
callback = function(ctx)
local message = ctx:require_arg("message")
ctx:respond("Noted: " .. message, { ephemeral = true })
end,
})
bot:run(os.getenv("TOKEN") or "YOUR_BOT_TOKEN")