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
    • Calculadora

0

120
Vistas
DisTubeError [INVALID_TYPE]: Expected 'number' for 'volume', but got '50' discord.js V13

I am trying to make a Discord music bot. All the code work fine but in the Volume command, I get this error when I execute !volume 50 :

throw new __1.DisTubeError("INVALID_TYPE", "number", volume, "volume");
                  ^
DisTubeError [INVALID_TYPE]: Expected 'number' for 'volume', but got '50'

This is my code :

const { guild, channel, member } = message;
if (
  member.roles.cache.has('926674590200123502') ||
  member.roles.cache.has('945435842258808862') ||
  member.roles.cache.has('928717168001024020') ||
  member.roles.cache.has('935939126123974726') ||
  member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)
) {
  const voicechannel = member.voice.channel;

  if (!voicechannel)
    return message.reply(
      'You must be in a voice channel to use Music commands',
    );

  if (guild.me.voice.channelID && voicechannel.id !== guild.me.voice.channelID)
    return message.reply(
      `I am already playing music in <#${guild.me.voice.channelID}>`,
    );

  const volume = args[0];

  if (volume > 100 || volume < 1)
    return message.reply('the volume must be a number between 1 and 100');

  await client.distube.setVolume(voicechannel, volume);
  await message.reply(`🔊 volume set to ${volume}`);
} else return message.reply("You can't use this command");

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

0

It's because '50' is not a number but a string. Try to parse it first:

const volume = parseInt(args[0], 10);

if (isNaN(volume)) 
  return message.reply('Volume must be a valid number');
if (volume > 100 || volume < 1 )
  return message.reply('Volume must be a number between 1 and 100');
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.