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

156
Views
how to ignore the discord API errors? Discord js V12

so I've asked this question before, so I made the command "dm-role" here's the code

const { Client, Message, MessageEmbed } = require('discord.js');
//const { join } = require('path');

module.exports = {
    name: 'dm-role',
    /** 
     * @param {Client} client 
     * @param {Message} message 
     * @param {String[]} args 
     */
     run: async(client, message, args) => {
    if (!message.member.hasPermission("ADMINISTRATOR")) return message.channel.send("admin only lol")

    if (!args[0]) return message.channel.send("where's the role?")
    const role = message.mentions.roles.first()

    message.guild.roles.cache.get(role.id).members.forEach(member => member.send(args.slice(1).join(" ")))

    if (!role) return message.channel.send("where's the role?")

    const reason = args.slice(1).join(" ")
    if (!reason) return message.channel.send("the message ?");

    try {
      
        await role.send(reason).catch(error => console.log(error))
        return message.channel.send("done");
    } catch {
        return message.channel.send("failed");
    }
}   
}


so the problem is, I got the error like this enter image description here

enter image description here

I don't know why I get errors like that, even though I've used .catch(error => console.log(error)) and this code used to run fine when my server was still 800+ members and now my server and now since my server has 1500+members, I get an error like that.

Is it because bots can't send 1500+ messages?

I hope someone can help me, Thank you (:

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Look into what calls are causing the errors, but if you want to ignore error messages as in not have them show in the console use:

.catch(error => null);

If using try/catch:

try {
   ...
} catch (err) {
   return;
}

It's best to not use both then/catch and try/catch as they are synchronous vs asynchronous respectively. Stick to one throughout your procedures. Whatever executes .catch() will execute catch () {}

try {
   await role.send(reason);
} catch (err) {
   console.error(err);
}
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!