Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
I have a little problem with a certain command in discord.js

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+/)```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!