Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Channel cache is not populated in recent GitHub versions #530

Closed
Ovyerus opened this issue Nov 5, 2023 · 1 comment
Closed

Channel cache is not populated in recent GitHub versions #530

Ovyerus opened this issue Nov 5, 2023 · 1 comment

Comments

@Ovyerus
Copy link
Contributor

Ovyerus commented Nov 5, 2023

I recently had to upgrade one of my bots to use a version of Nostrum from Git due to the recent changes from Discord that's pretty much broken past versions, but I've noticed that Nostrum.Cache.ChannelCache seems to be completely unpopulated now, even with requesting all intents from Discord.

On 0.8.0 ChannelCache was working fine.

Reproduction steps & code is available at https://github.com/Ovyerus/nostrum-channel-cache-repro

@jb3
Copy link
Collaborator

jb3 commented Apr 17, 2024

Firstly, I am so sorry for taking so long to reply to you on this.

As mentioned in the breaking changes recently:

The ChannelCache will no longer look up channels in the GuildCache if they
were not found in the channel cache itself. [...]

The Channel Cache, as documented here, is built to only store Direct Messages. All cached guild channels are stored with the associated guild.

The correct way to fetch these channels is something like the following (tested on the current master):

iex(20)> channel_id = 1229955694258684005
1229955694258684005
iex(21)> guild_id = Nostrum.Cache.ChannelGuildMapping.get(channel_id)
1226944827137069107
iex(22)> {:ok, guild} = Nostrum.Cache.GuildCache.get(guild_id)
{:ok,
 %Nostrum.Struct.Guild{
   id: 1226944827137069107,
   name: "nostrum test",
   ...
 }}
iex(24)> guild.channels[channel_id].name
"test"

I hope this helps, and again I am so sorry that this was not seen/replied to until now!

@jb3 jb3 closed this as completed Apr 17, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants