message.reply() function takes more than 10 minutes to send message

I'm running multiple bots on the same machine, and the problem that has been happening is that the message.reply() function is taking a long time to execute in busy chats, like general server chats. What's even weirder is that if the bot needs to reply to a message in another chat, it will do without delay.
MessageCreateEvent

if (message.content === `<@${clientID}>`) {
const helpMessage = [
'Olá, eu sou a **Kally**!',
`> Para ver meus comandos, use \`${guildSettings.preferences.prefix}ajuda\``,
`> Esta é minha versão **${
this.discord.isMaster ? 'Grátis' : 'Premium'
}**`,
]

const row = new ActionRowBuilder<ButtonBuilder>()

if (process.env.SUPPORT_LINK)
row.setComponents(
new ButtonBuilder()
.setLabel('Servidor de Suporte')
.setStyle(ButtonStyle.Link)
.setURL(process.env.SUPPORT_LINK)
)

return message.reply({
content: helpMessage.join('\n'),
components: [row],
})
}
MessageCreateEvent

if (message.content === `<@${clientID}>`) {
const helpMessage = [
'Olá, eu sou a **Kally**!',
`> Para ver meus comandos, use \`${guildSettings.preferences.prefix}ajuda\``,
`> Esta é minha versão **${
this.discord.isMaster ? 'Grátis' : 'Premium'
}**`,
]

const row = new ActionRowBuilder<ButtonBuilder>()

if (process.env.SUPPORT_LINK)
row.setComponents(
new ButtonBuilder()
.setLabel('Servidor de Suporte')
.setStyle(ButtonStyle.Link)
.setURL(process.env.SUPPORT_LINK)
)

return message.reply({
content: helpMessage.join('\n'),
components: [row],
})
}
This is not the only place that has delay, anywhere in the application I am using .reply() or .send() it will take a long time to execute just in chats with many messages being sent by users. (various messages, like conversations , interactions, etc). I don't know if it could have something to do with some kind of cache that discord.js does, or if it has a connection with the amount of bots that are running on my machine. This issue starts to happen just after few hours of running the bot
8 Replies
d.js toolkit
d.js toolkit•15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs•15mo ago
Ratelimits are dynamically assigned by the API based on current load and may change at any point. - The scale from okay to API-spam is sliding and depends heavily on the action you are taking - Rainbow roles, clock and counter channels, and DM'ing advertisements to all members are all examples of things that are not okay
LuaN
LuaN•15mo ago
@qjuh What I don't understand is why the bot would RateLimit if it's not spamming messages, and if I restart the bot it goes back to responding normally in the channel. If it was RateLimit I would have to wait some time even after restarting the application Removing GuildsMessage intents would mean removing moderation systems, levels, auto-responders, and many other features that make my bot popular within its target audience. Intents my bots use: Guilds | GuildBans | GuildMessages | GuildMembers | GuildEmojisAndStickers | GuildMessageReactions | GuildVoiceStates | MessageContent | GuildInvites My system is similar to what MEE6, Sapphire and other great bots have, which is the "custom bot", where the user can have an exclusive bot instance for his server, being able to change the name and photo of the bot CPU and RAM usage is very low, mainly because I pay per use, this has consumed less than 700MB and 0.8 vCPU But this problem has been with me since when I used a vps from Germany, I switched to cost per use because of the ease of application maintenance and the ease of scaling. I have recently been using fly.io services for this, where I can increase or decrease the machine's processing capacity according to the application's needs I believe that if it were a processing problem, it would not make sense for the bot to respond in other channels without delay, and it would take time to respond only in busy server chats Bots are still able to perform their tasks normally, such as searching the database, getting information from the Discord api. It seems that only the functions of reply and send messages in chats have this problem, possibly due to cache processing issues or something related
d.js docs
d.js docs•15mo ago
Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
client
.on("debug", console.log)
.on("warn", console.log)
- Note: if you initialize your Client as bot or other identifiers you need to use these instead of client - If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
LuaN
LuaN•15mo ago
@qjuh I've been monitoring it for a while, and debug hasn't given me any problems. I also added some logs before the reply function is called, and after the function returns a reply. All bots are receiving the logs: "[WS => Shard 0] Heartbeat acknowledged, latency of 119ms." And the log calling "finished reply" that is sent after the bot manages to send its response, takes the time that the response takes to be sent, which is on average 10 minutes
LuaN
LuaN•15mo ago
My memory usage
LuaN
LuaN•15mo ago
It looks like there is something inside the "reply" function that interacts with the discord api that is taking a long time to execute based on specific channels and servers after a certain amount of time. In a conversation on the discord developer server, they said that the time is too high to be a problem connecting to Discord, I believe that possibly it is something within the .send() and .reply() functions, because as I said before, in other channels the bot continues to respond without delay, even though in the channel where many messages have been sent the bot has not yet responded and if I restart the bot, it returns to responding normally in the channel where many messages are being sent
MessageCreateEvent

if (message.content === `<@${clientID}>`) {
const helpMessage = [
'Olá, eu sou a **Kally**!',
`> Para ver meus comandos, use \`${guildSettings.preferences.prefix}ajuda\``,
`> Esta é minha versão **${
this.discord.isMaster ? 'Grátis' : 'Premium'
}**`,
]

const row = new ActionRowBuilder<ButtonBuilder>()

if (process.env.SUPPORT_LINK)
row.setComponents(
new ButtonBuilder()
.setLabel('Servidor de Suporte')
.setStyle(ButtonStyle.Link)
.setURL(process.env.SUPPORT_LINK)
)

console.log("before the function") // it's getting here without delay

return message.reply({
content: helpMessage.join('\n'),
components: [row],
}).then(() => {
// it's taking more than 10 minutes to get here if the channel has a lot of users chatting over a certain period of time
// if it's on a channel where there aren't many users talking, it's coming here without delay
console.log("after reply")
})
}
MessageCreateEvent

if (message.content === `<@${clientID}>`) {
const helpMessage = [
'Olá, eu sou a **Kally**!',
`> Para ver meus comandos, use \`${guildSettings.preferences.prefix}ajuda\``,
`> Esta é minha versão **${
this.discord.isMaster ? 'Grátis' : 'Premium'
}**`,
]

const row = new ActionRowBuilder<ButtonBuilder>()

if (process.env.SUPPORT_LINK)
row.setComponents(
new ButtonBuilder()
.setLabel('Servidor de Suporte')
.setStyle(ButtonStyle.Link)
.setURL(process.env.SUPPORT_LINK)
)

console.log("before the function") // it's getting here without delay

return message.reply({
content: helpMessage.join('\n'),
components: [row],
}).then(() => {
// it's taking more than 10 minutes to get here if the channel has a lot of users chatting over a certain period of time
// if it's on a channel where there aren't many users talking, it's coming here without delay
console.log("after reply")
})
}
the delay time seems to increase as the chat remains active, gradually i dunno if this function has any synchronous task or something related that ends up taking a long time until the execution of the response
monbrey
monbrey•15mo ago
Are you listening to the rateLimited event to see if thats the cause? You could also enable the rejectOnRateLimit rest option
Want results from more Discord servers?
Add your server