Interaction already replied while it isn't

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
24 Replies
d.js toolkit
d.js toolkit•3w ago
Amgelo
Amgelo•3w ago
you must have replied to it already then share your command handler's code and your command's code
Dynastic Creator
Dynastic CreatorOP•3w ago
SourceBin
C1
Instantly share your code with the world.
Amgelo
Amgelo•3w ago
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
d.js docs
d.js docs•3w ago
:property: BaseInteraction#client discord.js@14.21.0 The client that instantiated this
Dynastic Creator
Dynastic CreatorOP•3w ago
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.');
};
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.');
};
Dynastic Creator
Dynastic CreatorOP•3w ago
when the cmd is run the eventhandler runs, looks for event folder, then the sub folder name is used as event name,
No description
Amgelo
Amgelo•3w ago
and what about leaderboardGraveyard?
Dynastic Creator
Dynastic CreatorOP•3w ago
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;
}
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;
}
Amgelo
Amgelo•3w ago
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
Dynastic Creator
Dynastic CreatorOP•3w ago
yeah, it load the cmd, the sub cmd is then called form that file: https://sourceb.in/rS3Hxgaacx
SourceBin
c2
Instantly share your code with the world.
Amgelo
Amgelo•3w ago
looks fine I think, can you share the full error?
Dynastic Creator
Dynastic CreatorOP•3w ago
is it clear?
No description
Dynastic Creator
Dynastic CreatorOP•3w ago
i mean the img
Amgelo
Amgelo•3w ago
ah, that's the dapi error, not the djs one it's likely you have two different processes handling the same command
Dynastic Creator
Dynastic CreatorOP•3w ago
hm
Dynastic Creator
Dynastic CreatorOP•3w ago
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
No description
Amgelo
Amgelo•3w ago
if you stop that process, does the bot still reply?
Dynastic Creator
Dynastic CreatorOP•3w ago
on running the cmd i get this error but i still get leaderboard embed
Amgelo
Amgelo•3w ago
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
Dynastic Creator
Dynastic CreatorOP•3w ago
So is it a discord error? I have been some other bots taking alot more time to respond and sometimes it doesn't even execute. For example the Sapphire bot.
Amgelo
Amgelo•3w ago
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
Dynastic Creator
Dynastic CreatorOP•3w ago
Ahh... Wait this line cleared my issue, i already have a host running my bot 😅
d.js toolkit
d.js toolkit•3w ago
The thread owner has marked this issue as solved.

Did you find this page helpful?