Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow ChannelManager#fetch without a guild #4929

Closed
1 task done
GamingGeek opened this issue Oct 23, 2020 · 4 comments · Fixed by #6034
Closed
1 task done

Allow ChannelManager#fetch without a guild #4929

GamingGeek opened this issue Oct 23, 2020 · 4 comments · Fixed by #6034

Comments

@GamingGeek
Copy link
Contributor

Please describe the problem you are having in as much detail as possible:
When using ChannelManager#fetch for a channel that is not cached and is not in any guilds on the current cluster, I get null rather than the channel

image

Using client.api works fine

image

Include a reproducible code sample here, if possible:

client.channels.fetch("channelID", false, true) // the channelID likely needs to be a channel accessible to the bot but not accessible to any guilds in the shards of the current process

Further details:

  • discord.js version: 12.4.0
  • Node.js version: 14.14.0
  • Operating system: Ubuntu Server 18.04
  • Priority this issue should have – please be realistic and elaborate if possible: Medium

Relevant client options:

  • partials: ["REACTION", "MESSAGE", "CHANNEL", "GUILD_MEMBER", "USER"]
  • gateway intents: 1607
  • other: shardCount is 4 and the shards on the cluster with the issue are [2, 3] whereas the channel in question is on shard 0
  • I have also tested the issue on latest master, commit hash: 250c3ae
@NotSugden
Copy link
Contributor

NotSugden commented Oct 23, 2020

the channel you're trying to fetch is from a guild which is not on the current shard, that seems to be the only explanation for this

if (!channel) {
this.client.emit(Events.DEBUG, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
return null;
}
here is the only way ChannelManager#fetch would return a promise resolving with null

either way there is definetly a problem here, perhaps an error should be thrown if the guild is for another shard, this would have to be for v13 however

@GamingGeek
Copy link
Contributor Author

@NotSugden It's fetching from the Rest API which is agnostic of shards/clusters meaning it should still work. Using the same method ChannelManager#fetch uses to fetch the channel from the API works as seen in this image so I'm not quite sure what's happening here.

@wasdennnoch
Copy link
Contributor

The issue lies in Channel#create where it only creates a d.js channel instance if the parent guild is known:


Since this shard is not aware of the guild the channel you're fetching is in, that method will never create a d.js Channel object, since that requires a parent guild object to exist in the current shard's client.
So the issue is not the API call - that works just fine - but the internal structure of Discord.js, in which a GuildChannel always has to have a known parent Guild object.

@GamingGeek
Copy link
Contributor Author

GamingGeek commented Oct 24, 2020

in which a GuildChannel always has to have a known parent Guild object.

Well that kinda ruins what I was working on. Maybe instead of this being a bug report, it could be a suggestion to make fetching a channel without a guild possible.

@iCrawl iCrawl changed the title ChannelManager#fetch returning null for a valid channel Allow ChannelManager#fetch without a guild Jul 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants