LogoLogo
  • What is WildBeast?
  • Guides
    • Linux guides
      • Setup
      • Running as a service
  • Fundamentals
    • Commands
      • Slash commands
        • Subcommands
        • Options
        • Buttons
      • Context menu actions
    • Jobs
  • Extras
    • VPS recommendations
    • Creating a bot account
    • Adding your bot to your server
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Fundamentals
  2. Commands
  3. Slash commands

Buttons

Add buttons for easy follow ups

PreviousOptionsNextContext menu actions

Last updated 3 years ago

Was this helpful?

Buttons are a simple way to create follow ups after a slash command has finished.

In practise

import { Interaction } from 'detritus-client'
import { ComponentContext, Components, Embed } from 'detritus-client/lib/utils'
import fetch from 'node-fetch'

import { BaseSlashCommand } from '../base'

export default class RandomCatCommand extends BaseSlashCommand {
  name = 'cat'
  description = 'Sends a random cat image'

  async run (context: Interaction.InteractionContext | ComponentContext): Promise<void> {
    const components = new Components({
      timeout: 5 * (60 * 1000),
      onTimeout: async () => await context.editOrRespond({ components: [] })
    })
    components.addButton({
      emoji: '🔃',
      run: async (componentContext: ComponentContext) => {
        await this.run(componentContext)
      }
    })
    const { fact } = await (await fetch('https://catfact.ninja/fact')).json()
    const embed = new Embed()
      .setDescription(fact)
      .setImage(`https://cataas.com/cat?${context.interaction.id}`) // cache busting
      .setFooter('Powered by cataas.com')
    await context.editOrRespond({
      embed,
      components
    })
  }
}