Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!