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

338
Vistas
discord.js v13 minecraft-server-util assertion error when getting the option of port

I am currently making a Minecraft server checker command using minecraft-server-util but everytime I enter the port number in the port option, the error AssertionError [ERR_ASSERTION]: Expected 'port' to be a 'number', got 'object' comes out. I am currently using the new interaction thing in discord.js v13.

Code:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageAttachment } = require('discord.js');
const util = require('minecraft-server-util');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('minecraft')
        .setDescription('Checks the status of a minecraft server.')
        .addStringOption(option => option.setName('address').setDescription('Enter the server address.').setRequired(true))
        .addNumberOption(option => option.setName('port').setDescription('Enter the server port. (25565 IS THE DEFAULT PORT)').setRequired(true)),
    async execute(interaction, client, MessageEmbed) {
        let server = interaction.options.getString('address');
        let serverPort = interaction.options.getNumber('port');

        if(serverPort == NaN) return interaction.reply({ content: 'The server port you provided is not a number.', ephemeral: true });

        util.status(server, { port: parseInt(serverPort)}).then((response) => {
            var fav = response.favicon.split(",").slice(1).join(",");
            var imageStream = Buffer.from(fav, "base64");
            var attachment = new MessageAttachment(imageStream, "favicon.png");
            const embed = new MessageEmbed()
            .setColor('#008000')
            .setTitle('Minecraft Server Status')
            .attachFiles([attachment])
            .addFields(
                {name: 'Server IP', value: response.host},
                {name: 'Online Players', value: response.onlinePlayers},
                {name: 'Player Threshold', value: response.maxPlayers},
                {name: 'MOTD', value: response.motd.clean},
                {name: 'Version', value: response.version},
            )
            .setThumbnail("attachment://favicon.png")
            interaction.reply({ embeds: [embed] })
        })
        .catch ((error) => {
            interaction.reply({ content: 'There was an error finding this server.', ephemeral: true });
            throw error;
        })
    },
};

It still won't work even if I change .addNumberOption into .addStringOption and parse serverPort into an integer using parseInt(serverPort).

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

0

The error is that you pass an object as the second parameter here: util.status(server, { port: serverPort }) while it should be the port number:

return util.status(server, serverPort)

Another thing, serverPort == NaN is always false. Even NaN == NaN is false. You should use isNaN instead:

let serverPort = NaN

console.log(serverPort == NaN)
console.log(serverPort === NaN)
console.log(isNaN(serverPort))

Although I'm not sure if it's ever NaN, as getNumber() returns the value of the option, or null if not set and not required.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Seems like it has something to do with my PC because when I hosted it on Heroku, it seems to have worked. util.status(server, serverPort) seems to work better than { port: parseInt(serverPort) }

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