Inconsistent results when sending a large volume of webhook messages

I’m new to node.js and discord.js, the previous version of this bot was written in (now deprecated).

This function iterates through all the webhooks (id and token) in my SQL database and sends a message to each of them. There are about 1500 of them (one for each server). I have to send a message roughly every 5 seconds. This worked perfectly in the python version, but that only had to run on about 300 guilds. I don’t have the code for it anymore, but it worked the same way (all the requests were sent at once, probably about 300 requests in 500ms and this worked fine), so I don’t think this is a rate limit issue.

    client.on('messageCreate', (message) => {
        if (message.channelId === '906659272744665139') {
            console.log('found message');
                const url = message.content;
                var webhooklist = [];
                //get all the webhooks from the database
                db.prepare('SELECT * FROM webhooks').all().forEach(webhook => {
                    const webhookclient = new WebhookClient({id: webhook.webhookID, token: webhook.webhookToken});
                var failed = 0;
                webhooklist.forEach(webhook => {
                    var row = new MessageActionRow()
                    webhook.send({content: url, components: [row]})
                        .catch(err => {
                            if (err instanceof DiscordAPIError) {
                                if (err.code === 10015) {
                                    //remove the webhook from the database
                                    db.prepare('DELETE FROM webhooks WHERE webhookID = ?').run(;
                                    console.log(`Removed webhook ${}`);
                            } else {
                                failed += 1;
                        } else {
                            failed += 1;

The problem:
A request is sent to each webhook, however, the messages don’t actually get sent half the time. For example, I’m looking at 3 different servers that this bot is in, and in one of them a message appeared and in the other two it didn’t (any other combination of these outcomes also occurs, its not a problem with how the servers are set up). There are also no errors, indicated by the failed variable. To clarify, about 50% of the messages get through, but the other 50% are supposedly sent by the bot but never appear in the channel.

Things that are (most likely) NOT the issue:

-Discord Rate limits
Why: Sending messages through webhooks does not count against the bot’s sent messages, and therefore will not cause rate limits (the global 50 messages per second). The only way this would cause me to be rate limited is if I was exceeding the 5/5 rate limit for each webhook individually (this is the same as what happens when you try to spam one channel).

-API rate limits
Why: API rate limits would only trip if I sent more than 10,000 invalid requests in 10 minutes. All of the requests go through, and there are no errors in the console. If I was being API rate limited, I would get completely blocked from using the discord API for up to an hour.

-I’m setting off some sort of spam protection
I’ve already considered this. Since most of the messages get through, I don’t think this is the problem. If I did set off any filters regarding volume of requests, the requests would probably either time out, or I would get blocked.

Other notes:

-A delay between requests is not a viable solution because pretty much any amount of delay multiplied by the 1500 times this has to run would result in this function taking multiple minutes to run.

-This could be related to another issue I’m having, where buttons take a long time to respond to so the interactions will often time out before I can even run .deferReply(), however, none of the webhook requests time out (which suggests that this may not be the issue)

-my internet has seemed slow recently even though I have gigabit, but again, if internet was the issue there would be errors.

In conclusion, a large volume of webhook messages like this SHOULD work, so this issue is most likely client-side.