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

233
Visualizações
Can't catch an Invalid Form Body error discord.js

I am trying to make a command to send an embed based on given JSON data, and it works, sort of.

I give the bot the data, and if it is correct, it will send it to the channel, which is perfect, exactly what I need it to do. BUT, if someone tries to put text in a link section, it will crash the bot. I tried try catch but it wont catch for some reason.

Error: Scheme "(my string that is not a url)" is not supported. Scheme must be one of ('http', 'https').

        try {
            let json = message.content.split(" ")
            json.shift() //get rid of the command bit, leaving the JSON
            let data = json.join(" ")
            let embedjson = new Discord.MessageEmbed(JSON.parse(data))
            message.channel.send({ embeds: [embedjson]}) //this works, unless it meets the problem listed above.
        } catch (error) { // >:( wont catch it
            let errorembed = new Discord.MessageEmbed()
            console.log(error)
            .setTitle('Error!')
            .setDescription(`Something went wrong! There are a few possible issues:\n1. You tried to put text in a link option (Like putting 'hello' in the image option, or 'never gonna give you up' in the thumbnail option.)\n2. Something else\nI'll attatch the error below:`)
            .addField('Error Message', error)
            message.channel.send({ embeds: [errorembed]})
        }

Any suggestions as to how I can catch the error? Any help is much appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe Discord.JS's client has an error event which could just log the error instead of crashing the node instance

Example:

client.on('error', (err) => {
    console.log(err)
})

Your code will still error, but your application will continue running. Not ideal, but a good solution if there is no other way.

You may also use process.on('error'), whichever floats your boat

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