flora is a fast and secure runtime that lets you write discord bots for your servers, with a rich TypeScript SDK, without worrying about running infrastructure. [mirror]
1function buildPong(args) {
2 const suffix = args.length > 0 ? ` (${args.join(' ')})` : ''
3 return `pong${suffix}`
4}
5
6const ping = prefix({
7 name: 'ping',
8 description: 'Respond with pong',
9 run: async ctx => {
10 await ctx.reply(buildPong(ctx.args))
11 }
12})
13
14const hello = slash({
15 name: 'hello',
16 description: 'Say hello',
17 options: [
18 {
19 name: 'name',
20 description: 'Who to greet',
21 type: 'string',
22 required: false
23 }
24 ],
25 run: async ctx => {
26 const name = ctx.options.name || 'world'
27 await ctx.reply({
28 content: `Hello, ${name}!`,
29 ephemeral: true
30 })
31 }
32})
33
34const counter = slash({
35 name: 'counter',
36 description: 'A simple counter using KV storage',
37 subcommands: [
38 {
39 name: 'get',
40 description: 'Get current count',
41 run: async ctx => {
42 const store = kv.store('counters')
43 const count = await store.get('main')
44 await ctx.reply(`Current count: ${count || 0}`)
45 }
46 },
47 {
48 name: 'increment',
49 description: 'Increment the counter',
50 run: async ctx => {
51 const store = kv.store('counters')
52 const current = parseInt((await store.get('main')) || '0', 10)
53 const newCount = current + 1
54 await store.set('main', String(newCount))
55 await ctx.reply(`Count is now: ${newCount}`)
56 }
57 },
58 {
59 name: 'reset',
60 description: 'Reset the counter',
61 run: async ctx => {
62 const store = kv.store('counters')
63 await store.set('main', '0')
64 await ctx.reply('Counter reset to 0')
65 }
66 }
67 ]
68})
69
70createBot({
71 prefix: '!',
72 commands: [ping],
73 slashCommands: [hello, counter]
74})
75// # sourceMappingURL=default_guild_bundle.js.map