So I'm making a discord bot which has a function to dm someone via slash command. Now how do i check if the user selected in the slash command is a bot or an actual user?
The slash command registerer
{
'name': 'dm',
'description': 'Dm someone if you are an admin',
'type':1,
"default_member_permissions": 'ADMINISTRATOR',
'options': [
{
'name': 'user',
'description': 'which user do you wanna dm?',
'type': 6,
'required': true
},{
'name': 'message',
'description': 'The message you wanna send',
'type':3,
'required': true
}
]
}
The logic
client.on('interactionCreate', (interaction) =>{
if (!interaction.isChatInputCommand) return;
if (interaction.commandName === 'apanker'){
if (interaction.options.getSubcommand() === 'dm'){
const message = interaction.options.getString('message')
if (interaction.options.getUser('user') === interaction.user.bot) {
interaction.reply(({ content: `Bots can't be`, ephemeral: true }))
}
else{
const rec = interaction.options.getUser('user')
const user = interaction.user.id
try {
rec.send({ embeds:[ new EmbedBuilder().setDescription(`<@${user}> says to you: ${message} `).setColor("#f05c51")
.then(interaction.reply(({ content: 'Successfully sent', ephemeral: true })))
] })
} catch (error) {
interaction.reply(({ content: `Could not send message, maybe dm's off? -> ${error}`, ephemeral: true }))
}
}
}
}
})
But the if (interaction.options.getUser('user') === interaction.user.bot) does not work
There is a .bot property which you may use to check if the user is a bot or not.
const user = interaction.options.getUser("user");
if (user.bot) {
console.log("User is bot");
} else {
console.log("User isn't bot")
};