Skip to content

🔮 magical era of hooks#51

Merged
notunderctrl merged 2 commits intoneplextech:masterfrom
twlite:magic
Jan 8, 2024
Merged

🔮 magical era of hooks#51
notunderctrl merged 2 commits intoneplextech:masterfrom
twlite:magic

Conversation

@twlite
Copy link
Member

@twlite twlite commented Jan 4, 2024

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
Copy link

vercel bot commented Jan 4, 2024

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 twlite changed the title 🔮 magic era of hooks 🔮 magical era of hooks Jan 4, 2024
@twlite
Copy link
Member Author

twlite commented Jan 4, 2024

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

@coltasa
Copy link
Contributor

coltasa commented Jan 5, 2024

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
Copy link
Member Author

twlite commented Jan 6, 2024

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

@notunderctrl notunderctrl merged commit 7ed0d40 into neplextech:master Jan 8, 2024
@twlite twlite deleted the magic branch January 8, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants