#subcommand not showing

33 messages ยท Page 1 of 1 (latest)

halcyon dawn
#

When i try to do the instagram command the subcommand isn't showing

cursive larkBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • 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!
halcyon dawn
#

not receiving any error at all

uneven knot
#

Did you deploy the command?

halcyon dawn
#

you mean like this

        await client.application?.commands.fetch();
        await client.application?.commands.set(commands);
        console.log(`Synced ${commands.length} commands globally`);
uneven knot
#

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

halcyon dawn
#

alright i will fix that later on

#

but to answer your question then yeah, i did deploy my command

uneven knot
#

Now restart your Discord app (Ctrl + R)

halcyon dawn
#

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;
}

uneven knot
#

Log your commands. Is the subcommand there?

halcyon dawn
#

you mean like this

uneven knot
#

No, the full command data

halcyon dawn
#

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
}

uneven knot
halcyon dawn
#

i tried both tbh

stuck hazel
# halcyon dawn 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

halcyon dawn
#

i just do get this return

content: 'โŒ Please specify a valid subcommand. Use /instagram config setup or /instagram config status.',

halcyon dawn
stuck hazel
halcyon dawn
stuck hazel
#

Yeah so you did not re deploy

halcyon dawn
#

it does automatically right when restarting the bot

uneven knot
# halcyon dawn

Add console.log(interaction.commandGuildId) to your command execute function. Does it log the id?

halcyon dawn
#

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

uneven knot
#

Probably you didn't save the file

halcyon dawn
#

i did ๐Ÿ˜„

#

always the first time i do check

#

but it is fixed so whatever