#Creeper - await and username
1 messages · Page 1 of 1 (latest)
well if the client.users.fetch() has an invalid id passed
then the whole app crashes
so i want to make the value null if it doesn't return a value
but i am not sure how to do that
So it's that the fetch errors, or returns undefined?
yes the error is coming from the fetch
if i do fetch('123') i want it to return null but instead it crashes the whole app
You're 100% fetch itself is throwing an error, not that because it returns nothing, .username then errors?
Do you have the error trace?
You sure the Id is a User Id, sounds like you made a magical Id
i made the value an invalid id but i want to make it so it doesnt crash to program and instead it returns null
like the username variable should be equal to null
it used to work when i used to use client.users.cache.get() because that is not a promise and it just returns null if there is no value but then i noticed that i need to use .fetch() instead and now i get this error
In this case if you want to protect it from erroring, just move the username 1 out.
and put it in a try catch
let username;
try {
username = (await ...)
} catch (error) {
username = 'N/A';
}
NP
its just alot more lines than what i had before but thanks