SlashCommandBuilder error

Im trying to make a command that would dm a specified user a embed. I am aware that there have been questions like this, but I didnt really understood them very well. Error in screenshots import { SlashCommand } from "../types"; import { ColorResolvable, EmbedBuilder, SlashCommandBuilder } from "discord.js"; ``ts const command : SlashCommand = { command: new SlashCommandBuilder() .setName("dm") .setDescription("Send a user a custom embed message") .addUserOption(option => option .setName("user") .setDescription("User to send the message to") .setRequired(true) ) .addStringOption(option => option .setName("title") .setDescription("Title of the embed message") .setRequired(true) ) .addStringOption(option => option .setName("description") .setDescription("Description of the embed message.") .setRequired(true) ) .addStringOption(option => option .setName("color") .setDescription("Select an option or type a hex color, e.g., #000000") .setRequired(true) ), execute: async (interaction) => { try { const user = interaction.options.getUser("user"); if (!user) { interaction.reply({ content: "User not found.", ephemeral: true }); return; } const title = interaction.options.getString("title")!; const description = interaction.options.getString("description")!; const color = interaction.options.getString("color") as ColorResolvable; const embed = new EmbedBuilder() .setColor(color) .setTitle(title) .setDescription(description) .setFooter({ text: "Test123", iconURL: interaction.client.user?.avatarURL() || undefined }); await user.send({ embeds: [embed] }); interaction.reply({ content: "Embed message successfully sent.", ephemeral: true }); } catch (error) { console.error(Error: ${error.message}`); interaction.reply({ content: "Something went wrong...", ephemeral: true }); } }, cooldown: 10 } export default command
11 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
Squid
Squid10mo ago
When you add a non-subcommand option to a slash command builder, then the type of that builder now omits the methods to add subcommands, as shown in the error You should include that Omit<...> type for your custom type SlashCommand#command
Acemavie
Acemavie10mo ago
you mean add it to here? export interface SlashCommand { command: SlashCommandBuilder, execute: (interaction : ChatInputCommandInteraction) => void, autocomplete?: (interaction: AutocompleteInteraction) => void, cooldown?: number // in seconds }
Squid
Squid10mo ago
Yes
Acemavie
Acemavie10mo ago
Not exactly sure how to do that tbh
Squid
Squid10mo ago
command: SlashCommandBuilder | Omit<SlashCommandBuilder, ...> Use the TS error to see which methods are omitted
Acemavie
Acemavie10mo ago
Like this? export interface SlashCommand { command: SlashCommandBuilder | Omit<SlashCommandBuilder, ...>, execute: (interaction: ChatInputCommandInteraction) => void, autocomplete?: (interaction: AutocompleteInteraction) => void, cooldown?: number // in seconds } Probably something is wrong bc there are some errors
Squid
Squid10mo ago
It's not literally ... I just don't feel like typing the method names out on mobile
Acemavie
Acemavie10mo ago
Oh I mightunderstand now
Squid
Squid10mo ago
Acemavie
Acemavie10mo ago
these three dots are types? Thanks! Got it working