slash command type issue

./lib/types/command.ts:
export type Command = {
category: Category
data: SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | ContextMenuCommandBuilder
execute?: (i: ChatInputCommandInteraction, client: Client) => void
}
export type Command = {
category: Category
data: SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | ContextMenuCommandBuilder
execute?: (i: ChatInputCommandInteraction, client: Client) => void
}
userinfo.ts:
const data = new SlashCommandBuilder()
.setName("userinfo")
.setDescription("Get the info of a user")
.setDMPermission(true)
.setNSFW(false)
.addUserOption(option =>
option
.setName("user")
.setDescription("The user to get the info of")
)

const userinfo: Command = {
category: "utility",
data,
async execute(i, client) {...}
}
const data = new SlashCommandBuilder()
.setName("userinfo")
.setDescription("Get the info of a user")
.setDMPermission(true)
.setNSFW(false)
.addUserOption(option =>
option
.setName("user")
.setDescription("The user to get the info of")
)

const userinfo: Command = {
category: "utility",
data,
async execute(i, client) {...}
}
Error (ts 2322)

Type

Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">
is not assignable to type

SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | ContextMenuCommandBuilder
Error (ts 2322)

Type

Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">
is not assignable to type

SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | ContextMenuCommandBuilder
how do I fix this issue? like if I add Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup"> it gets fixed but then there can I'll have to add more like "addBooleanOption" | "addUserOption" | ....., I just want it to be a slashcommand builder, it can have subcommands or not, or just options, etc.
2 Replies
d.js toolkit
d.js toolkit16mo 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. - Issue solved? Press the button!
Shaurya
ShauryaOP16mo ago
^14.11.0 and v18.16.0 for now, I did:
type toOmit = "addSubcommand" | "addSubcommandGroup" | "addBooleanOption" | "addUserOption" | "addChannelOption" | "addRoleOption" | "addAttachmentOption" | "addMentionableOption" | "addStringOption" | "addIntegerOption" | "addNumberOption"

export type Command = {
category: Category
data: Omit<SlashCommandBuilder, toOmit> | ContextMenuCommandBuilder
execute?: (i: ChatInputCommandInteraction, client: Client) => void
}
type toOmit = "addSubcommand" | "addSubcommandGroup" | "addBooleanOption" | "addUserOption" | "addChannelOption" | "addRoleOption" | "addAttachmentOption" | "addMentionableOption" | "addStringOption" | "addIntegerOption" | "addNumberOption"

export type Command = {
category: Category
data: Omit<SlashCommandBuilder, toOmit> | ContextMenuCommandBuilder
execute?: (i: ChatInputCommandInteraction, client: Client) => void
}
but I don't think this is the best way to do it, I just want to set it as a SlashCommandBuilder not wanna check if it's subCommandsOnly, or a few things are ommited, etc but I don't wanna define a lot of types there though yes the pick seems to be working well and not breaking other commands, until now I only had commands of type SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder so didn't need a check, but the userinfo command was none of them and was ommiting subcmd and subcmdGroup
Want results from more Discord servers?
Add your server