So I'm making a bot for myself to do stuff, and I tried to make a kill command
if (CMD_NAME == "kill") {
let target = message.mentions.members.first()
message.reply(`${target} is die`)
}
and I came to the conclusion that the bot doesn't know what is message.mentions.members.first() in general, how do I fix that? Also if I need to show more code, tell me
Edit: how I coded in the prefix:
if (message.author.bot) return;
if (message.content.startsWith(PREFIX)) {
const [CMD_NAME, ...args] = message.content
.trim()
.substring(PREFIX.length)
.split (/\/s+/)```
Based on comments under your question, I think your problem might be somewhere else.
const PREFIX = "!"
let str = "!a b c"
const [CMD_NAME, ...args] = str.trim().substring(PREFIX.length).split(/\/s+/)
console.log(CMD_NAME)
console.log(args)
outputs:
a b c
[]
So it appears that your code is putting whole msg as "command name" which probably makes it fail name check and that's why nothing at all happens.
Changing that split regex to /\s+/ to properly detect whitespaces changes the output to:
a
[ 'b', 'c' ]
which would probably fix your issue.