#subcommand not showing
33 messages ยท Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
Did you deploy the command?
you mean like this
await client.application?.commands.fetch();
await client.application?.commands.set(commands);
console.log(`Synced ${commands.length} commands globally`);
Yeah, but don't deploy commands each bot startup. You can be rate limited easily. It's better to have a separate file and run it when you have done changes to the data
alright i will fix that later on
but to answer your question then yeah, i did deploy my command
Now restart your Discord app (Ctrl + R)
i already tried
and it has nothing to do with this file right
import { Client, Collection, ApplicationCommandData } from "discord.js";
import fs from "fs";
import path from "path";
import { fileURLToPath, pathToFileURL } from "url";
import dotenv from "dotenv";
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// ๐ Make sure it loads from the correct directory
const commandsDir = path.join(__dirname, "../commands");
function getCommandFiles(dir: string): string[] {
return fs.readdirSync(dir, { withFileTypes: true })
.flatMap(dirent =>
dirent.isDirectory()
? getCommandFiles(path.join(dir, dirent.name))
: dirent.name.endsWith(".ts") && !dirent.name.includes("handler")
? path.join(dir, dirent.name)
: []
);
}
export async function setupCommandHandler(client: Client): Promise<ApplicationCommandData[]> {
if (!client.commands) client.commands = new Collection();
const commandFiles = getCommandFiles(commandsDir);
const commands: ApplicationCommandData[] = [];
console.log(`๐ Found ${commandFiles.length} command files`);
for (const filePath of commandFiles) {
try {
const commandModule = await import(pathToFileURL(filePath).href);
const command = commandModule.default || commandModule;
if (command?.data?.name) {
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
console.log(`โ
Loaded command: ${command.data.name}`);
} else {
console.log(`โ ๏ธ Skipping invalid command file: ${filePath}`);
}
} catch (error) {
console.error(`โ Error loading command from ${filePath}:`, error);
}
}
return commands;
}
Log your commands. Is the subcommand there?
you mean like this
No, the full command data
so like this
๐ Command Structure for: instagram
{
"options": [
{
"type": 2,
"name": "config",
"description": "Configure Instagram integration",
"options": [
{
"type": 1,
"name": "setup",
"description": "Set up Instagram integration",
"options": [
{
"channel_types": [
0
],
"name": "channel",
"description": "Channel to post Instagram updates",
"required": true,
"type": 7
}
]
},
{
"type": 1,
"name": "status",
"description": "Check Instagram integration status",
"options": []
}
]
}
],
"name": "instagram",
"description": "Manage Instagram integration",
"default_member_permissions": "8",
"type": 1
}
Have you used the shortcut, not just closed and open the app?
i tried both tbh
Did you try to run that command? If it is outdated discord will tell you and auto-refresh your commands, if not then you didn't deploy your commands properly
i just do get this return
content: 'โ Please specify a valid subcommand. Use /instagram config setup or /instagram config status.',
this is correct deploying right so i don't see the issue then
What does it show in discord? Can you show that?
Yeah so you did not re deploy
it does automatically right when restarting the bot
Add console.log(interaction.commandGuildId) to your command execute function. Does it log the id?
now i do get this error
This command is outdated, please try again in a few minutes
after adding this console log it did refresh
wtf
Probably you didn't save the file