#Interaction already replied while it isn't

37 messages · Page 1 of 1 (latest)

dense rapids
#

Whenever I run a cmd which has deferReply() at start of execution, I get that interaction is already replied. It's not being defered from what I can log in terminal but still got the issue

agile auroraBOT
harsh maple
#

you must have replied to it already then

#

share your command handler's code

#

and your command's code

dense rapids
harsh maple
#

show where you call onCommandsInteraction and leaderboardGraveyard

#

also you don't need to send your client alongside the interaction, every djs object already has a reference to the client, including interactions

jade valveBOT
dense rapids
#

the event handler hanldes the calls:

import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import { getFilePaths, getFolderPaths } from '#services/filesManager/getPaths.js';
import { createLogger } from '#utils/globalUtils/logger.js';

const logger = createLogger('EventLoader');

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
 * Loads and registers all event listeners from the "events" folder.
 *
 * @param {import('discord.js').Client} client - The Discord client instance.
 */
export default (client) => {
  const eventFolders = getFolderPaths(path.resolve(__dirname, '..', 'events'));

  logger.info('Registering event listeners...');

  for (const eventFolder of eventFolders) {
    const eventFiles = getFilePaths(eventFolder);
    eventFiles.sort();

    // Extract event name from folder path
    const eventName = eventFolder.replace(/\\/g, '/').split('/').pop();

    // Set up event listener
    client.on(eventName, async (...args) => {
      for (const eventFile of eventFiles) {
        try {
          const eventFileURL = pathToFileURL(eventFile).href;
          const eventModule = await import(eventFileURL);

          if (eventModule.default) {
            await eventModule.default(client, ...args);
          } else {
            logger.warn(`No default export in event file ${eventFile}`);
          }
        } catch (err) {
          logger.error(`Error executing event function from file ${eventFile} for event ${eventName}`, err.message);
        }
      }
    });

    logger.debug(`Registered listener for event: ${eventName}`);
  }
  logger.success('All event listener registered successfully.');
};

#

when the cmd is run the eventhandler runs, looks for event folder, then the sub folder name is used as event name,

harsh maple
#

and what about leaderboardGraveyard?

dense rapids
#

when the cmd is run the the cmd file is looked up and then the assoicated sub cmd is ran

#
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import { getFilePaths, getFolderPaths } from '#services/filesManager/getPaths.js';
import { createLogger } from '#utils/globalUtils/logger.js';

const logger = createLogger('CommandLoader');

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
 * Loads all local command modules from the `/commands` directory recursively.
 * Each command file must default-export a command object.
 *
 * @returns {Promise<Array<Object>>} Resolves to an array of command definitions.
 */
export default async function getLocalCommands() {
  const localCommands = [];

  const commandsDir = path.join(__dirname, '../../commands');
  const commandCategories = getFolderPaths(commandsDir);

  for (const commandCategory of commandCategories) {
    // Get all command files in the current category (folder)
    const commandFiles = getFilePaths(commandCategory);

    // Iterate over each command file
    for (const commandFile of commandFiles) {
      try {
        // Convert the path to a file:// URL before import
        const fileURL = pathToFileURL(commandFile).href;
        const commandModule = await import(fileURL);

        if (commandModule?.default) {
          localCommands.push(commandModule.default);
          logger.debug(`Loaded command from file: ${commandFile}`);
        } else {
          logger.warn(`No default export found in: ${commandFile}`);
        }
      } catch (err) {
        logger.error(`Error loading command from file: ${commandFile}`, err.message);
      }
    }
  }

  return localCommands;
}
harsh maple
#

that only loads commands though, not subcommands

#

leaderboardGraveyard isn't even default-exported

#

it's a named export, it suggests you're importing it manually and calling it

dense rapids
harsh maple
#

looks fine I think, can you share the full error?

dense rapids
#

is it clear?

#

i mean the img

harsh maple
#

ah, that's the dapi error, not the djs one

#

it's likely you have two different processes handling the same command

dense rapids
#

hm

#

this is what i can see on running the leaderboard cmd one time, i don't think other process would be handling the same process

harsh maple
#

if you stop that process, does the bot still reply?

dense rapids
#

on running the cmd i get this error but i still get leaderboard embed

harsh maple
#

yeah that does sound like you have another process

#

if it was in the same process you'd get the djs error

#

djs stores in the interaction whether it has already been replied, but obviously it only knows about replies on its own process, it doesn't know about others'

#

if it has stored that the interaction has been replied, and you reply again, it'll throw a djs error, since that'll throw an api error anyways if it does get sent

#

but you're getting the api error, so djs doesn't know it has already been replied to, it was done by a different process

dense rapids
harsh maple
#

that'd be a different kind of error, and no, as I said, your interaction is being handled by another process, you'll need to figure which and kill it

#

or you can reset your token, it'll logout any existent connections

dense rapids
#

Ahh... Wait

dense rapids