Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
Discord.js DND Dice Roll Input Change Number

I've made a "working" dice roll function on my bot. Works fine for what I need, but was wondering how I could make it so depending on what is said in discord it rolls.

So saying !rolld6 would use 6 in var response instead of 20.

if (message.content.toLowerCase().includes("!rolld20")) {
const ayy = client.emojis.cache.find(emoji => emoji.name === "diceroll");
var response = [Math.floor(Math.random() * ((20 - 1) + 1) + 1)];
            message.channel.send(`${ayy}` + `Rolling.`)
                .then(msg => {
                    setTimeout(function() {
                        msg.edit(`${ayy}` + `Rolling..`)
                    }, 1000);
                    setTimeout(function() {
                        msg.edit(`${ayy}` + `Rolling...`)
                    }, 2000)
                    setTimeout(function() {
                        msg.edit(`${ayy}` + `Rolling....`)
                    }, 3000)    
            setTimeout(function() {
                        
            msg.edit(`${ayy}` + " Rolled... " + response + " " + `${ayy}`).then().catch(console.error)  
                    }, 4000)    
            
                })


return;
}

Not even sure what I would search to figure this out so any help is greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use a regular expression instead of .includes, and then extract the digits after the d to randomize.

You don't need to subtract 1, then add 1 right after that - those cancel out, nor do you need to put the result into an array - interpolating just the random number generated into the message will work fine.

const match = message.content.match(/!rolld(\d+)/i);
if (match) {
    const die = match[1];
    const response = 1 + Math.floor(Math.random() * die);    
    const ayy = client.emojis.cache.find(emoji => emoji.name === "diceroll");
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda