#SlashCommandBuilder error

1 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