My bot doesn't get the full list of channels on a server
Hi there! I'm working on a bot that posts messages in a channel and I've just noticed that this functionality no longer works. I did some digging and it seems that not all channels are listed when using
client.channels.cache
. I checked all permissions, and viewed the server by using the bot's role and everything looks fine, my bot is supposed to see the relevant channels, but when I do this:
only a subset of all visible channels is returned. I double checked and the channel id I'm using (myChannelId
) is good, but it is not in the list. Am I supposed to invalidate the cache somehow? What am I missing?16 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!As long as you have the Guilds intent and you didn't fuck around with a custom channel cache, all normal channels should be cached
someone suggested a while ago that I shouldn't do anything so I didn't ...
but now I tried this
and the channel suddenly appeared
what am I doing wrong?
or when am I supposed to
fetch
stuff?
this is how I initialize my client
I don't have any custom caches
this worked a few weeks ago and I didn't change the code
and it suddenly stopped working, but if I do the fetch
before touching the cache it works againwhat type of channel is it
regular text channel
can you log
guild.channels.cache.map(c => c.name + ' - ' + c.id)
for me and show the output?
Before fetching anything, preferrably in the ready eventsure
integration-test
is the one we're looking for
hm
this is in a test, so i have no client ready
this is what I have in my test
so await
-ing client.login
doesn't await the ready event?the ready event is emitted after the client received all guilds, not after the method login completes
can i await client ready (without the callback)?
as this is not compatible with how tests work
i mean after
beforeEach
returns the client should be ready
so preferably tehre should be something like client.awaitReady()
or something similar
?:node:
nodeEventTarget.once(type, listener)
Node.js-specific extension to the EventTarget
class that adds a once
listener for the given event type
. This is equivalent to calling on
with the once
option set to true
.😅
huh
where do I import this from?
oh got it
let's see
I didn't try that so far
an abstraction that I use to hide the actual implementation
I have
SlackAgent
, TestAgent
and so on
I .skip
these tests by default
I only use it when I need to check the actual result in the channel
all the utility functions are tested separately, and the actual discord interaction is not run by default
I also have a TestAgent
that's effectively a mock for all my agents
I added await once(client, Events.ClientReady);
and now I dont' need fetch
anymore, thanks
there is one thing though
sending messages is extremely slow
i have some logic that chunks up my messages so that I can send embeds without reaching the limit
but sometimes sending only a few messages to a channel takes 10+ seconds
i realized this when I had a db transaction open accidentally and my code failed because the transaction manager have already closed the transaction by the time discord.js finished
what could be the reason for this slowness?
rate limiting?
to give you some context: this bot sends daily reports to a channel (and also in dms), so a report usually consists of some headers (2-3 embeds), and 5-20 reports (1 embed each) depending on the team size
also i think i found the real issue. one of my test users probably closed dms and i get a promise rejection so the rest of the list doesn't get the dms
hm
what are the rate limits?
I'm gonna chunk everything so that I can minimize the amount of messages sentRatelimits are dynamically assigned by the API based on current load and may change at any point.
- The scale from okay to API-spam is sliding and depends heavily on the action you are taking
- Rainbow roles, clock and counter channels, and DM'ing advertisements to all members are all examples of things that are not okay
how do you test whether the call actually works then?
this is all I have though
![No description](https://cdn.answeroverflow.com/1237406624809750528/image.png)