What I am trying to do is have a counter that is shown in the name of a channel.
I am aware of the Discord API rate-limits and that I can change the channel name 2 times in 10 minutes. I am aware that DiscordJS handles rate-limits internally by putting them in a queue.
The problem is right here, suppose the bot executes these lines consecutively:
myChannel.setName(1);
myChannel.setName(2);
myChannel.setName(3);
myChannel.setName(4);
myChannel.setName(5);
What happens is that the first two requests change the channel name and the other three go to queue. But after 10 minutes what happens is that the third and fourth requests are sent, while I would like to jump to the last one instead.
I was interested in finding out if there was a way to check the response to the request for a channel name change, in order to "intercept" the rate-limit and prevent it from going into the queue.
I have already thought of a solution for the problem itself:
setInterval(()=>{
myChannel.setName(varDefSomewhereElse);
},10*60*1000);
but I want to solve the "problem" as efficiently as possible.
Two ways would likely work for this:
try {
myChannel.setName('asd')
}
catch (error) {
console.error(error)
// handle the error here
}
myChannel.setName(varDefSomewhereElse).then((c) => {
console.log(`Set to ${c.name}`)
})