MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Welcome/goodbye.js:35–123  ·  view source on GitHub ↗
(interaction)

Source from the content-addressed store, hash-verified

33 .setRequired(false))),
34
35 async execute(interaction) {
36 const deferSuccess = await InteractionHelper.safeDefer(interaction);
37 if (!deferSuccess) {
38 logger.warn(`Goodbye interaction defer failed`, {
39 userId: interaction.user.id,
40 guildId: interaction.guildId,
41 commandName: 'goodbye'
42 });
43 return;
44 }
45
46 const { options, guild, client } = interaction;
47
48 if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)) {
49 return await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'You need the **Manage Server** permission to use `/goodbye`.' });
50 }
51
52 const subcommand = options.getSubcommand();
53
54 if (subcommand === 'setup') {
55 const channel = options.getChannel('channel');
56 const message = options.getString('message');
57 const image = options.getString('image');
58 const ping = options.getBoolean('ping') ?? false;
59
60 const existingConfig = await getWelcomeConfig(client, guild.id);
61 if (existingConfig?.goodbyeChannelId) {
62 logger.info(`[Goodbye] Setup blocked because config already exists in channel ${existingConfig.goodbyeChannelId} for guild ${guild.id}`);
63 return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'Goodbye is already configured for <#${existingConfig.goodbyeChannelId}>. Use **/goodbye config** to customize channel, message, ping, or image.' });
64 }
65
66 if (!message || message.trim().length === 0) {
67 logger.warn(`[Goodbye] Empty message provided by ${interaction.user.tag} in ${guild.name}`);
68 return await replyUserError(interaction, { type: ErrorTypes.VALIDATION, message: 'Goodbye message cannot be empty' });
69 }
70
71 if (image) {
72 try {
73 new URL(image);
74 } catch (e) {
75 logger.warn(`[Goodbye] Invalid image URL provided by ${interaction.user.tag}: ${image}`);
76 return await replyUserError(interaction, { type: ErrorTypes.VALIDATION, message: 'Please provide a valid image URL (must start with http:// or https://' });
77 }
78 }
79
80 try {
81 await updateWelcomeConfig(client, guild.id, {
82 goodbyeEnabled: true,
83 goodbyeChannelId: channel.id,
84 leaveMessage: message,
85 goodbyePing: ping,
86 leaveEmbed: {
87 title: "Goodbye {user.tag}",
88 description: message,
89 color: getColor('error'),
90 footer: `Goodbye from ${guild.name}!`,
91 ...(image && { image: { url: image } })
92 }

Callers

nothing calls this directly

Calls 7

getWelcomeConfigFunction · 0.90
updateWelcomeConfigFunction · 0.90
getColorFunction · 0.90
formatWelcomeMessageFunction · 0.90
replyUserErrorFunction · 0.85
safeDeferMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected