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

145
Views
Having trouble getting a command that sends based on the amount entered to work

I'm trying to make a command that repeats a message based on the number that you input. For example, if I did -ping 4 it would say pong back 4 times. My code for the functionality of the command at the moment (separate from the main file) is:

async execute(message, args) {
    if(!args[1]) return message.channel.send("`Command Usage:\n-rqplay (amount)`");
    if(isNaN(args[1])) return message.channel.send("Please enter an actual number idiot :rolling_eyes:");
    
    if(args[1] > 15) return message.channel.send("I don't want to send that many messages :nauseated_face:");
    if(args[1] < 1) return message.reply("Bro come on, are this stupid?");
    
    await message.channel.messages.fetch({limit: args[1]}).then(_messages =>{
        message.channel.send('@everyone play');
    });
}

However the bot only returns with one command. Help would be much appreciated, thanks!

I'm using the latest Discord.js, VSCode, and node.js.

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

0

With await message.channel.messages.fetch({limit: args[1]}) you are fetching the channel's messages with a limit of whatever number they provided.

If you would like to send a message to the channel however many times they provided, you could use this:

async execute(message, args) {
        if(!args[1]) return message.channel.send("`Command Usage:\n-rqplay (amount)`");
        if(isNaN(args[1])) return message.channel.send("Please enter an actual number idiot :rolling_eyes:");

        if(args[1] > 15) return message.channel.send("I don't want to send that many messages :nauseated_face:");
        if(args[1] < 1) return message.reply("Bro come on, are this stupid?");

        for (let i = 0; i < args[1]; i++) {
           message.channel.send('@everyone play');
        }
    }
}

Notice the for loop at the bottom used to send the messages.

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!