Trying to change a variable inside a CATCH
well i have a piece of that im trying to send message to a specific amount of people and im trying to find out how many people didnt get the message.
so im trying to +1 to a number variable in my CATCH when sending the message but it never gets added. ( if i console.log it shows the error , but my variable doesnt change )
9 Replies
- 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!
- ✅
Marked as resolved by OPyour approach is wrong, all im gonna say is that you shouldnt use a forEach while doing async stuff, since this is not working the way you think it is. use a
for of
loop instead with async await. I dont think i can help you too much because this is potentially api spam, also potentially mass dming users which is against Discord developers TOSwell it cant be called api spam , i mean i can also set a delay between each message.
and dming the users is something they want actually ( its a feature for a community so they get important messages in their dms ).
ill try it with for of loop , will post the results here , thanks
will also read TOS carefully to see if my case is excluded or not 😉
even in non-spam use cases, discord has explicitly advised against mass dms regardless of consent
mentions and announcement channels are preferred
Mass DMing users is not allowed as per developer ToS, considered spam and can get you and your bot banned.
- Mention
@everyone
to inform all your users at once instead
- Discord Developer Terms of Service: learn more | FAQ summarywell i did it with for of loop and it still had the same result ,
i dont know if i said it wrong , but also i used to do it without async while using foreach .
and that variable error doesnt change in the catch its like it kinda skip it.
its not only in this case , its also in other cases that i wanna show to the discord manager to tell them how many didnt people didnt get the message , ( like for notification messages , ( those who pop in and get new notifications and i wanna know how many users didnt ).
but that variable never gets changed in .catch , is it even possible to change a varriable in .catch?
yea
there are multiple ways to achieve it
if you chain a .catch() to the promise, just return something like null from it and then check the return value
value = await promise().catch(() => null)
if value equals null
variable++
continue
well yeah thanks , the issue was mainly with the await , async promises , but yeah its fixed now ^^