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

173
Views
Discord.js v13 why is this code not working?

I wanted to make my bot say whatever I tell it to by using a command. I have the code copied from other parts of my bot and it is working there yet here it just doesn't and I can't understand why. There are no error messages. Here's my code:

const { Permissions } = require('discord.js');

module.exports = {
    name: 'say',
    description: "Sprawia że coś mówię.",
    execute(message, args)
    {
        let text = args.join(" ").slice(22);
        if(text)
        {
            message.channel.send(text)
        }
        else 
        {
            message.reply('test')//show correct usage
        }
    }
}

(const {Permissions} will be used later so don't worry about it being there) Also you can see what it looks like on discord: here.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The code is working exactly how you have programmed it. Take a look at this line:

let text = args.join(" ").slice(22);

Assuming your args in the test case "rp say xd" are just supposed to be "xd", the above code is entirely wrong. The code combines the args, separating them with spaces, and then gets a substring of that starting from the 22nd character. In other words, for text to be anything other than an empty string, your args would have to be over 22 characters long ("rp say xdddddddddddddddddddd!" would make text equal just the ending "!").

Because text is always an empty string for args under 22 characters long, you are basically just doing if (""), which is the same as doing if (false). This means your else statement will always run, unless your args are over 22 characters long combined.

To fix this, do something like this instead:

let text = args.join(" ");

Or, if you meant to make your bot only use the first 22 characters of args provided to it:

let text = args.join(" ").slice(0, 22); //.slice(startIndex, endIndexExclusive)
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!