i'm curently trying to implement a discord bot using https://github.com/izy521/discord.io that reacts to all messages with letters in a specific order. if one of those calls should fail, it is supposed to repeat it again until it succeeds before moving on to the next letter.
in my example im trying to react with the letters "A" and "G" in that particular order, but when spamming messages the reactions will somtimes not be in order.
async function reactUntilSuccess(mID, channelID, letter){
await bot.addReaction({channelID,messageID: mID,reaction: letter},
async function(err,res){
if (err==null){
//reaction sucessul, continue to next letter
return;
}
else {
//wait a bit and try again
await sleep(200)
await reactUntilSuccess(mID, channelID, letter)
}
})
}
//reacts with A and G to message
async function reactString(mID, channelID){
await asyncForEach(["??","??"], async (letter) => {
//is supposed to wait until last letter is finished before reacting with next letter
await reactUntilSuccess(mID, channelID, letter)
await sleep(1000)
})
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
bot.on('message', function (user, userID, channelID, message, evt) {
mID = evt.d.id;
reactString(mID, channelID, message);
})
how do i make it so that my reactString function actually waits until the previous reactions are done?
question from:
https://stackoverflow.com/questions/65840416/do-asynchronous-calls-in-order-and-repeating-on-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…