Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

339
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda