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]
1import { buildPong } from './utils/reply'
2
3// Prefix command example
4const ping = prefix({
5 name: 'ping',
6 description: 'Respond with pong',
7 run: async (ctx) => {
8 await ctx.reply(buildPong(ctx.args))
9 }
10})
11
12// Slash command example
13const hello = slash({
14 name: 'hello',
15 description: 'Say hello',
16 options: [
17 {
18 name: 'name',
19 description: 'Who to greet',
20 type: 'string',
21 required: false
22 }
23 ],
24 run: async (ctx) => {
25 const name = (ctx.options.name as string) || 'world'
26 await ctx.reply({
27 content: `Hello, ${name}!`,
28 ephemeral: true
29 })
30 }
31})
32
33// Slash command with subcommands
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
70// Register the bot
71createBot({
72 prefix: '!',
73 commands: [ping],
74 slashCommands: [hello, counter]
75})