#Interaction already replied while it isn't
37 messages · Page 1 of 1 (latest)
you must have replied to it already then
share your command handler's code
and your command's code
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
BaseInteraction#client [email protected]
The client that instantiated this
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,
and what about leaderboardGraveyard?
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;
}
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
yeah, it load the cmd, the sub cmd is then called form that file:
https://sourceb.in/rS3Hxgaacx
looks fine I think, can you share the full error?
ah, that's the dapi error, not the djs one
it's likely you have two different processes handling the same command
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
if you stop that process, does the bot still reply?
on running the cmd i get this error but i still get leaderboard embed
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
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.
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
Ahh... Wait
this line cleared my issue, i already have a host running my bot 😅