Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

43
Vistas
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.

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos