Search…
Buttons
Add buttons for easy follow ups
Buttons are a simple way to create follow ups after a slash command has finished.

In practise

1
import { Interaction } from 'detritus-client'
2
import { ComponentContext, Components, Embed } from 'detritus-client/lib/utils'
3
import fetch from 'node-fetch'
4
5
import { BaseSlashCommand } from '../base'
6
7
export default class RandomCatCommand extends BaseSlashCommand {
8
name = 'cat'
9
description = 'Sends a random cat image'
10
11
async run (context: Interaction.InteractionContext | ComponentContext): Promise<void> {
12
const components = new Components({
13
timeout: 5 * (60 * 1000),
14
onTimeout: async () => await context.editOrRespond({ components: [] })
15
})
16
components.addButton({
17
emoji: '🔃',
18
run: async (componentContext: ComponentContext) => {
19
await this.run(componentContext)
20
}
21
})
22
const { fact } = await (await fetch('https://catfact.ninja/fact')).json()
23
const embed = new Embed()
24
.setDescription(fact)
25
.setImage(`https://cataas.com/cat?${context.interaction.id}`) // cache busting
26
.setFooter('Powered by cataas.com')
27
await context.editOrRespond({
28
embed,
29
components
30
})
31
}
32
}
33
Copied!
Last modified 10d ago
Export as PDF
Copy link
Contents
In practise