I'm trying to create a warning command that DMs the specified user to notify them. Here is the specific code I'm trying to use:
const user = await client.users
.fetch(interaction.options.getString("user"), false)
.catch(() => null);
console.log(interaction.options.getString("user"));
const embed = new MessageEmbed()
.setColor("#FCE100")
.setTitle(`⚠️ Warning!`)
.setDescription(`${interaction.options.getString("warning")}`);
await user.send({ embeds: embed }).catch(() => {
interaction.channel.send(
"Error: user not found"
);
});
The getString for user is correctly getting the user, as I've tested from console.log(). I can only assume the syntax is somehow wrong, although I can't seem to find the correct way to do this. The only error I'm getting is:
TypeError: Cannot read properties of null (reading 'send')
You don't need to use .getString().
CommandInteractionOptionResolver#getString() does it for you.
Make sure that you have the user option type set to "USER" before doing the code below.
const user = interaction.options.getUser("user");
// ...