fix: consider #nsfw false if not present in data #4593
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please describe the changes this PR makes and why it should be merged:
As #4296 brought up, discord.js has
text
type channels in cache where the.nsfw
property returnsundefined
.Problem breakdown:
nsfw
in its channel data on initial guild payloadsThis PR attempts to fix this inconsistency by considering the channel to not be nsfw if the
.nsfw
key is not present in the initial channel data.Changes breakdown:
TextChannel
.nsfw
in the constructor withthis.nsfw = Boolean(data.nsfw);
.nsfw
in_patch
withif (typeof data.nsfw !== 'undefined') this.nsfw = Boolean(data.nsfw);
.nsfw
docstring into the constructor callStoreChannel
.nsfw
in the constructor withthis.nsfw = Boolean(data.nsfw);
.nsfw
in_patch
withif (typeof data.nsfw !== 'undefined') this.nsfw = Boolean(data.nsfw);
.nsfw
docstring into the constructor callFurther considerations:
From my own tests (sample size: 237 channels out of which 44 are affected) i can say that after requesting said channels through the raw API endpoint
GET /channels/:id
none of the "pending" nsfw properties weretrue
.Sinister Rectus, dev of discordia could also reproduce this behavior and they seem to handle this the same way.
According to sinister this is also done on
user.bot
where we do handle this properly by assigning theBoolean(data.bot)
in the constructordiscord.js/src/structures/User.js
Line 34 in d827544
and only patching if the value is not
undefined
discord.js/src/structures/User.js
Line 61 in d827544
I have applied this same reasoning to TextChannel and NewsChannel in this PR.
Typings considerations:
boolean
instead of?boolean
already, so this PR (fix) is consistent with the already applied typings.Status
Semantic versioning classification: