deact-component-callback
Handle Discord component interactions in Deact. Use when implementing button clicks, select menus, and user input.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Handle Discord component interactions in Deact. Use when implementing button clicks, select menus, and user input.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Add new moves to the battle system. Use when implementing attack, status, or support moves for Pokemon.
Add a Pokemon (real or fake) to src/config/pokemonConfig.js with its moves, abilities, rarity, and evolution data. Use when the user asks to add, register, implement, or create a new Pokemon, Pokemon form, or fake/custom Pokemon in the battle system.
Find a Pokemon's Discord emoji string — canonical (e.g. `<:25:1100282072003772457>`) from `pokestar-pk-{n}`, form variants (e.g. `<:483origin:1404654211324448848>`) from `pokestar-forms-1`, or fakemon (e.g. `<:ashpikachu:1109522092283658250>`) from `pokestar-pk-extra` — via Playwright CLI. Use when the user asks for a Pokemon's emoji, emoji ID, form emoji, fakemon emoji, or needs an `<:name:snowflake>` string.
Create an implementation plan before adding one or more Pokemon via the `add-pokemon` skill. Builds Pokemon, moves, and abilities tables with all required inputs, flags unimplemented moves/abilities, and produces step-by-step implementation instructions. Use when the user asks to plan adding a Pokemon, plan a Pokemon batch, or invokes this skill before `add-pokemon`.
Verify Discord bot changes by running the bot and testing commands in Discord via Playwright CLI. Use when the user asks to test, verify, or check bot commands in Discord.
Verify a Pokemon's configuration in pokemonConfig.js by testing its moves and abilities in Discord via Playwright CLI. Use when validating a Pokemon's battle behavior after configuration changes.
| name | deact-component-callback |
| description | Handle Discord component interactions in Deact. Use when implementing button clicks, select menus, and user input. |
Deact uses useCallbackBinding to connect Discord component interactions (buttons, select menus) to handler functions. The callback is invoked when a user interacts with the component.
const {
useState,
useCallbackBinding,
createElement,
} = require("../../deact/deact");
const Button = require("../../deact/elements/Button");
module.exports = async (ref, {}) => {
const [count, setCount] = useState(0, ref);
// 1. Create callback binding
const onClickKey = useCallbackBinding(() => {
setCount((c) => c + 1);
}, ref);
// 2. Pass to component
return {
components: [
[
createElement(Button, {
label: `Count: ${count}`,
callbackBindingKey: onClickKey,
}),
],
],
};
};
const callbackKey = useCallbackBinding(
(interaction, data) => {
// interaction: Discord MessageComponentInteraction
// data: Custom data object passed from component
},
ref,
options,
);
interaction.user - User who clickedinteraction.values - Selected values (for select menus)interaction.customId - Component ID (managed by Deact)Custom data passed via component's data prop:
createElement(Button, {
callbackBindingKey: myKey,
data: { action: "delete", itemId: 123 },
});
// In callback:
const callbackKey = useCallbackBinding((interaction, data) => {
console.log(data.action); // "delete"
console.log(data.itemId); // 123
}, ref);
useCallbackBinding(callback, ref, {
defer: true, // Defer interaction update (default: true)
userIdForFilter: ..., // Restrict who can interact
});
defer: true (default) - Deact handles the interaction responsedefer: false - Required when showing modals// Normal callback
const normalKey = useCallbackBinding(() => setValue(1), ref);
// Modal callback (defer: false required)
const modalKey = useCallbackBinding(
async (interaction) =>
await createModal(builder, props, submitKey, interaction, ref),
ref,
{ defer: false },
);
Callbacks can and almost always should be async:
const saveKey = useCallbackBinding(async (interaction, data) => {
await saveToDatabase(data.itemId);
setIsSaved(true);
}, ref);
Return an error object to show error message:
const actionKey = useCallbackBinding(async (interaction, data) => {
const result = await performAction(data.id);
if (result.err) {
return { err: result.err }; // Shows error to user
}
setData(result.data);
}, ref);
useCallbackBinding for buttons and select menususeModalSubmitCallbackBinding for modal submissionsdefer: false when opening modalsdata prop to identify which component triggered{ err: "message" } to show errorsuse-deact-hook - All available hooks including useCallbackBindingdeact-modal - Using modals with callbacksreferences/user-id-filter.md - Restricting who can interact with componentsreferences/button-callbacks.md - Button click patterns (simple, with data, toggle, shared)references/select-menu-callbacks.md - Select menu patternsreferences/pattern-yes-no.md - Yes/No confirmation patternreferences/pattern-pagination.md - Prev/Next pagination pattern