underctrl-io / commandkit

Only focus on what matters - Let CommandKit handle your commands and events in your Discord.js projects!
https://commandkit.js.org
MIT License
82 stars 9 forks source link

🔮 magical era of hooks #51

Closed twlite closed 6 months ago

twlite commented 6 months ago

This PR introduces hooks mode in commandkit. This is currently behind experimental flag and can be enabled like this:

const commandkit = new CommandKit({
  // ...
  experimental: {
    hooks: true // disabled by default
  }
});

Once this is enabled, commandkit runs in hooks mode. Command context is no longer passed as an argument, but through hooks.

// without hooks
export async function run({ interaction }: SlashCommandProps) {
  // do stuff
}

// with hooks
export async function run() {
  const interaction = useInteraction();
  // do stuff
}

Additionally, this PR also adds response function to safely reply to interaction

import { response, useGuild } from 'commandkit'

export async function run() {
  const guild = useGuild();
  if (!guild) {
    response({ content: 'You are in DMs' });
  } else {
    response({ content: 'You are in guild' });
  }
}
vercel[bot] commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
commandkit-docs ❌ Failed (Inspect) Jan 4, 2024 8:19pm
twlite commented 6 months ago

this is just a concept, feel free to close if this feels unnecessary for bots creation

NotM1Dev commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC) commandkit-docs ❌ Failed (Inspect) Jan 4, 2024 8:19pm

@twlite nahh even vercel hates you. i thought it was just netlify

twlite commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎ Name Status Preview Comments Updated (UTC) commandkit-docs ❌ Failed (Inspect) Jan 4, 2024 8:19pm

@twlite nahh even vercel hates you. i thought it was just netlify

yes