Cannot read properties of null when editing a automod rule
Description
When attempting to update an automod rule i get an error from discord.js that it can not read properties of null when reading 'autoModerationRules'.
Package
[email protected]
Node v20.7.0
Code
Both guild
and automodRule
exist and return valid objects
Error
The above leads to the following method, with the cursor after the .
after the guild
Any help would be appreciate, i am not sure what is causing this issue, thanks in advance.12 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 OPAlso, please ping me if you reply, so i can see that you have replied.
what intents do u have enabled in the client constructor
These are the ones enabled, i just added the Automod ones and tried again but it appears to have made no change.
do u use custom cache or sweepers?
in the docs it says <AutoModerationRuleManager>.guild isn't nullable so for me it looks like ur guild caches messed up or smth
i don't believe so
this is quite interesting because i am not sure if this is something i can fix
maybe the client isn't ready when u run this code, log
client.isReady()
yea it returns true
if anyone else has any ideas i would like to hear
just to add, using things like .setName() also do not work (they just call this.edit() so basically the same thing i am trying to do overall)
does a
rule.edit()
work fine for you?
going to go to bed now but if you know anything about this please comment i don't use automod but i havent seen anyone else who ran into this issue so i dont think its a problem with djs
yea it works for me
logs the 2 rules present in the guild
so should i be using the cache instead of directly fetching things?
strange
dang
So i switched it to get from the cache but that does not fix the issue, both
client.guilds.cache
and guild.autoModerationRules.cache
return what they should but i still get the null.
I get the rules originally with this code (below) do some stuff with it, then run the code above ( https://canary.discord.com/channels/222078108977594368/1198436552083247114/1198617628864938114 ) on it
Here is the full code of the sections
Rule config data looks like:
just return it to the api, i don't alter it.
Its just sending/receiving data between the bot and api through nats, i don't know the specifics as i was not the one to set it up
would there be a way for me to fix this issue without changing how that works? not particaly fond of doing a complete re-write of that system is weird because other stuff seems to work fine ty
Hi, even this isn't working
error:
@Woffer12
ok, even without it it doesnt work tho
oh
we fetched guilds on ready
but we kinda need it, is there no way around it?
i dont think this was a good idea to do on ready:
added this 3 months ago, pls no judging for the help 😊