-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_button.lua
More file actions
54 lines (42 loc) · 1.37 KB
/
Copy pathview_button.lua
File metadata and controls
54 lines (42 loc) · 1.37 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
-- examples/view_button.lua
-- Example: Buttons with a View.
--
-- Component callbacks receive a ComponentContext (ctx) with
-- respond/update/defer for answering the interaction.
local discord = require("../init")
local View = require("./ui/view")
local Button = require("./ui/button")
-- Only slash commands and component interactions here, no prefix
-- commands reading message content, so GUILDS alone is enough.
local bot = discord.Bot(nil, discord.enums.INTENTS.GUILDS)
local votes = { up = 0, down = 0 }
local vote_view = View.new({ timeout = 30000 })
vote_view:add(Button.new({
label = "Upvote",
style = "success",
custom_id = "vote_up",
}))
vote_view:add(Button.new({
label = "Downvote",
style = "danger",
custom_id = "vote_down",
}))
bot:interaction("vote_up", function(ctx)
votes.up = votes.up + 1
ctx:update("Votes: +" .. votes.up .. " / -" .. votes.down)
end)
bot:interaction("vote_down", function(ctx)
votes.down = votes.down + 1
ctx:update("Votes: +" .. votes.up .. " / -" .. votes.down)
end)
bot:component(vote_view)
bot:slash_command("poll", {
description = "Starts a simple upvote/downvote poll",
callback = function(ctx)
ctx:respond("Votes: +0 / -0", { components = vote_view:to_components() })
end,
})
bot:on("ready", function()
print("Bot is ready!")
end)
bot:run(os.getenv("TOKEN") or "YOUR_BOT_TOKEN")