Send message to specific channel
Hi i'm trying to get a list of textchannels to log to. But when i use client.channels.fetch i keep getting 'null'?
here's my code.
the config.SEXY_LOG_CHANNELS is an env var with the channels id seperated by commas.
21 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 OPI've also tried out
client.channels.cache.get(i);
and same thing with that one.first of all, all channels are cached by the Guilds intent, no need to fetch
second, check if your ids are valid
eg they arent stored as numbers
and log them
I'll try that thanks
The channel ids are correct
Also have the guild intent
and gave it permissions to the channel
the client has access to all channels regardless of permissions
if the cache returns nothing, the id is invalid
or the channel belongs to a guild the bot isnt in
not with the bot scope at least
I'll try to kick and invite it again to my server
it has the bot scope but it's till not returning the channel
when i right click the channel and press copy id i get
which is the same as the id in the logs
the weird part is it that it says that it isn't null (that's the 'false' at the end of the log)
but it's undefined
oh wait nvm that isn't weird the null part was only for .fetch and not .cache.get
when does this code run?
at command initalisation
ooooh
i'm such a moron
yeah your client isnt ready yet
that's before the client logs in
thank you
sorry for wasting your time lol
no worries
i have one final question
does registering commands need to happen before logging the client in?
it doesnt need to happen when logging it at all
its supposed to be a separate file
that you run when you make changes to your command data
ohh
running it every time your bot starts will lead to ratelimits
okay thanks