You can use message.mentions.has(bot.user)
to check if the bot is mentioned. Also, make sure you're passing the bot to your execute()
method instead of instantiate a new one:
module.exports = {
name: 'kill',
description: 'kills',
execute(message, args, bot) {
message.delete({ timeout: 30000 });
if (message.content.startsWith('!kill')) {
const target = message.mentions.users.first();
const memberTarget = message.guild.members.cache.get(target.id);
if (message.mentions.has(bot.user)) {
return message.channel.send(`HA! SIKE! <@${message.author.id}> died.`);
}
message.channel.send(`<@${memberTarget.user.id}> has died!`);
console.log(`<@${memberTarget.user.id} died.`);
}
},
};
And in your main JS file pass down the bot
object:
// ...
client.commands.get('kill').execute(message, args, bot)
// ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…