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

Channel.type undefined #10483

Closed
Calculamatrise opened this issue Sep 4, 2024 · 2 comments
Closed

Channel.type undefined #10483

Calculamatrise opened this issue Sep 4, 2024 · 2 comments

Comments

@Calculamatrise
Copy link

Which package is this bug report for?

discord.js

Issue description

  • Create a listener for the GuildMemberAdd/GuildMemberRemove events
  • Attempt to get/fetch a VoiceChannel type to send a message alert
  • Print out the channel type

Code sample

// GuildMemberAdd & GuildMemberRemove event listeners:
// 'entry' references a database entry
let channel = member.guild.channels.cache.get(entry.alerts.memberPart);
if (!channel) {
	channel = await member.guild.channels.fetch(entry.alerts.memberPart).catch(() => {
		// This isn't important, but I'll leave it here just in case
		this.database.guilds.update(member.guild.id, {
			alerts: { memberPart: null }
		})
	});
	if (!channel) {
		return;
	}
}
if (channel.type > 0) return;
// channel.type is returning undefined when it is a VoiceChannel instance. I ran an eval command to get the same channel by its ID and it shows channel.type as 2, so I'm not sure why this is happening. I

Versions

Discord.js: 14.15.2
Node: v20.15.1
npm: 10.8.3

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

@monbrey
Copy link
Member

monbrey commented Sep 4, 2024

Seems unlikely to be a bug, as a channel can't be constructed without a type unless Discord isn't providing one: https://github.com/discordjs/discord.js/blob/14.16.1/packages/discord.js/src/structures/BaseChannel.js#L23

Normally when I see this sort of issue, channel isn't actually a Channel type object at all. Could you log it and confirm that other than channel.type, the rest of the properties are as expected? My guess, without additional info, would be that you're fetching channels with an undefined value and actually returning a Collection.

@Calculamatrise
Copy link
Author

I apologize for the delayed response. I had to wait until the issue reoccurred so I can see what happened. I made a silly mistake. What happened was the channel id was being set (in the database) to false instead of null, and I was checking if it wasn't null, so it was returning a Collection instead of the target channel.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants