Search code examples
javascriptdiscord.jsdistube

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");


Solution

  • 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');