From 2fb33a3035fef530ff50741e1257ea1df9399e7f Mon Sep 17 00:00:00 2001 From: HadesCodesLikeAnIdiot Date: Tue, 2 Sep 2025 10:22:11 +0100 Subject: [PATCH] Monkey patched Events/InteractionHandler.js to make life easer (: --- Events/InteractionHandler.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Events/InteractionHandler.js b/Events/InteractionHandler.js index 9a7ba78..0ee3a1f 100644 --- a/Events/InteractionHandler.js +++ b/Events/InteractionHandler.js @@ -8,12 +8,39 @@ const ErrorParse = require('../Utils/FindError'); const { FANCY_ERRORS } = require('../config.json'); +const { CommandInteraction, MessageFlags } = require("discord.js"); + module.exports = { name: 'interactionCreate', execute: async function (client, interaction) { const BoundHandler = InteractionHandler.bind(null, client, interaction); + CommandInteraction.prototype.reply = (function (original) { + // Prevents the decrepitated "ephemeral" message in later discord.js versions. + // Also allows to use MessageFlags.IsComponentsV2 without needing to define "MesssageFlags" by simply doing v2: true + return async function (options) { + let messageFlags = []; + + if (options.v2) { + messageFlags.push(MessageFlags.IsComponentsV2); + delete options.v2; + } + + if (options.ephemeral) { + messageFlags.push(MessageFlags.Ephemeral); + delete options.ephemeral; + } + + if (messageFlags.length > 0) { + options.flags = (options.flags ?? 0) | + messageFlags.reduce((a, b) => a | b, 0); + } + + return original.call(this, options); + }; + })(CommandInteraction.prototype.reply); + switch (interaction.type) { case 4: // Autocomplete case 2: // Slash Commands + Context Menus