Reputation: 5
I am trying a discord bot with a modal, I want to send a private message to the user, but an error appears like this
Error: TypeError: user.send is not a function
this is my code
const invoke = async (interaction) => {
const user = interaction.user.id
const modal = new ModalBuilder({
customId: `createChar-${interaction.user.id}`,
title: 'Create Character',
});
const CharacterName = new TextInputBuilder({
customId: 'characterName',
label: 'Input your (fisrtname_lastname)',
style: TextInputStyle.Short,
});
const PasswordInput = new TextInputBuilder({
customId: 'characterPassword',
label: 'Input your Password',
style: TextInputStyle.Short,
});
const firstActionRow = new ActionRowBuilder().addComponents(CharacterName);
const secondActionRow = new ActionRowBuilder().addComponents(PasswordInput);
modal.addComponents(firstActionRow, secondActionRow);
await interaction.showModal(modal)
const filter = (interaction) => interaction.customId === `createChar-${interaction.user.id}`;
interaction
.awaitModalSubmit({ filter, time:30_000 })
.then((modalInteraction) => {
const CharacterName = modalInteraction.fields.getTextInputValue('characterName')
const PasswordInput = modalInteraction.fields.getTextInputValue('characterPassword')
const user = interaction.user.id
user.send(`ASDASD`) // <<<<< THIS IS MY CODE
modalInteraction.reply(`Your character name: ${CharacterName}\nYour Password: ${PasswordInput}\nMy discord ${interaction.user.id}`)
})
.catch((err) => {
console.log(`Error: ${err}`)
});
}
What am I doing wrong?
I want to send a private message when submitting the button modal
Upvotes: 0
Views: 34
Reputation: 311338
send
is a method of the user, not the user's id:
const user = interaction.user // was interaction.user.id in the question
user.send(`ASDASD`)
Upvotes: 3