Incorrect type in TypeScript?

I'm creating a bot with discord.js andTypeScript, so now i am creating a command with subcommands Everything was going fine, until I tried to get the name of the subcommand, where TypeScript alerts the following error: Property 'getSubcommand' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getAttachment" | ... 6 more ... | "getSubcommand">'.ts(2339) But, when executing this code, all run without problems... How can i solve this (without using //@ts-ignore) Here is the code:
import { readdirSync } from "fs";
import { Command, SubCommand } from "../../interfaces/Command";
import { SlashCommandBuilder } from "discord.js";

const subcommands = readdirSync("./discord/commands/sub/ticket").map(x => require("./sub/ticket/" + x).default as SubCommand);

const obj = {
name: "ticket",
description: "Gerencie seus tickets",
command: async (client, int, command) => {

const subcommand_name = int.options.getSubcommand();
const subcommand = subcommands.find(x => x.name == subcommand_name);

subcommand?.command(client, int, command);

},
button: async (client, int, command) => {},
slashData: new SlashCommandBuilder()
} as Command;

for (const file of subcommands) {
obj.slashData.addSubcommand(x =>
file.slashData
.setName(file.name)
.setDescription(file.description)
)
}

export default obj;
import { readdirSync } from "fs";
import { Command, SubCommand } from "../../interfaces/Command";
import { SlashCommandBuilder } from "discord.js";

const subcommands = readdirSync("./discord/commands/sub/ticket").map(x => require("./sub/ticket/" + x).default as SubCommand);

const obj = {
name: "ticket",
description: "Gerencie seus tickets",
command: async (client, int, command) => {

const subcommand_name = int.options.getSubcommand();
const subcommand = subcommands.find(x => x.name == subcommand_name);

subcommand?.command(client, int, command);

},
button: async (client, int, command) => {},
slashData: new SlashCommandBuilder()
} as Command;

for (const file of subcommands) {
obj.slashData.addSubcommand(x =>
file.slashData
.setName(file.name)
.setDescription(file.description)
)
}

export default obj;
2 Replies
d.js toolkit
d.js toolkit13mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
José
José13mo ago
OBS: The type of int is CommandInteraction<CacheType> I did this, but now i have a new problem... Firstly, see my event InteractionCreate
import { BaseInteraction, ChatInputCommandInteraction } from "discord.js";
import Bot from "../CustomClient";

const event = {
eventName: "interactionCreate",
function: async (client: Bot, int: BaseInteraction) => {

const command = client.commands.find(x => x.name == (int as ChatInputCommandInteraction).commandName);

if (int.isCommand()) await command?.command(client, int, command);
if (int.isButton()) await command?.button(client, int, command);

}
}

export default event;
import { BaseInteraction, ChatInputCommandInteraction } from "discord.js";
import Bot from "../CustomClient";

const event = {
eventName: "interactionCreate",
function: async (client: Bot, int: BaseInteraction) => {

const command = client.commands.find(x => x.name == (int as ChatInputCommandInteraction).commandName);

if (int.isCommand()) await command?.command(client, int, command);
if (int.isButton()) await command?.button(client, int, command);

}
}

export default event;
Well, in the block await command.command(client, int, command); i'm getting this problem when i try to convert int (who is BaseInteraction) to ChatInputCommandInteraction, as my function requires function type: (command.command(client: Discord.Client, int: ChatInputCommandInteraction, command: Command)):
Argument of type 'CommandInteraction<CacheType>' is not assignable to parameter of type 'ChatInputCommandInteraction<CacheType>'.
Property types 'commandType' are incompatible.
Type 'ApplicationCommandType' cannot be assigned to type 'ApplicationCommandType.ChatInput'.
Argument of type 'CommandInteraction<CacheType>' is not assignable to parameter of type 'ChatInputCommandInteraction<CacheType>'.
Property types 'commandType' are incompatible.
Type 'ApplicationCommandType' cannot be assigned to type 'ApplicationCommandType.ChatInput'.