mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-08 11:37:20 +00:00
feat: use a standard custom ID format in role buttons
This commit is contained in:
parent
784c54b22a
commit
b64611dd01
4 changed files with 30 additions and 3 deletions
|
@ -3,16 +3,22 @@ import { RoleButtonsPluginType, TRoleButtonOption } from "../types";
|
|||
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
|
||||
import { GuildMember } from "discord.js";
|
||||
import { getAllRolesInButtons } from "../functions/getAllRolesInButtons";
|
||||
import { parseCustomId } from "../../../utils/parseCustomId";
|
||||
|
||||
export const onButtonInteraction = typedGuildEventListener<RoleButtonsPluginType>()({
|
||||
event: "interactionCreate",
|
||||
async listener({ pluginData, args }) {
|
||||
if (!args.interaction.isButton() || !args.interaction.customId.startsWith("roleButtons:")) {
|
||||
if (!args.interaction.isButton()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { namespace, data } = parseCustomId(args.interaction.customId);
|
||||
if (namespace !== "roleButtons") {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = pluginData.config.get();
|
||||
const [, name, optionIndex] = args.interaction.customId.split(":");
|
||||
const { name, index: optionIndex } = data;
|
||||
// For some reason TS's type inference fails here so using a type annotation
|
||||
const buttons = config.buttons[name];
|
||||
const option: TRoleButtonOption | undefined = buttons?.options[optionIndex];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue