#SlashCommandBuilder error

16 messages · Page 1 of 1 (latest)

sage walrus
#

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

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
visual meteorBOT
#
  • 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!
  • Marked as resolved by OP
quasi field
#

You should include that Omit<...> type for your custom type SlashCommand#command

sage walrus
#

you mean add it to here?

export interface SlashCommand {
command: SlashCommandBuilder,
execute: (interaction : ChatInputCommandInteraction) => void,
autocomplete?: (interaction: AutocompleteInteraction) => void,
cooldown?: number // in seconds
}

quasi field
#

Yes

sage walrus
#

Not exactly sure how to do that tbh

quasi field
#

command: SlashCommandBuilder | Omit<SlashCommandBuilder, ...>

#

Use the TS error to see which methods are omitted

sage walrus
#

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

quasi field
#

It's not literally ...

#

I just don't feel like typing the method names out on mobile

sage walrus
#

Oh

#

I mightunderstand now

quasi field
sage walrus
#

these three dots are types?