interaction.channel.guildId undefined after ephemeral reply

Hello, I've been having an issue since updating my script to v14.16.1. The issue seems to be that responding to interactions with ephemeral messages can sometimes cause the guildId of the channel in the cache to become undefined. It does not happen every time, but usually occurs within 1-3 interactions. I have not been able to reproduce the error without the DirectMessages intent and Channel partial, even though the interaction is from a guild channel. The bot is installed in the guild and can view the channel. I'm thinking this is a bug, but if not, can someone explain why the behavior seems inconsistent? Thanks in advance. Minimum reproducible example:
const { Client, Events, GatewayIntentBits, Partials } = require("discord.js")
const { token } = require("./config.json")

const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
],
partials: [
Partials.Channel,
],
})

client.on(Events.InteractionCreate, async interaction => {
console.log(interaction.channel.guildId) // pass
await interaction.reply({ content: "content", ephemeral: true })
console.log(interaction.channel.guildId) // sometimes undefined
console.log(interaction.client.channels.resolve(interaction.channelId).guildId) // same
})

client.login(token)
const { Client, Events, GatewayIntentBits, Partials } = require("discord.js")
const { token } = require("./config.json")

const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
],
partials: [
Partials.Channel,
],
})

client.on(Events.InteractionCreate, async interaction => {
console.log(interaction.channel.guildId) // pass
await interaction.reply({ content: "content", ephemeral: true })
console.log(interaction.channel.guildId) // sometimes undefined
console.log(interaction.client.channels.resolve(interaction.channelId).guildId) // same
})

client.login(token)
Node v20.17.0 and [email protected]
No description
No description
6 Replies
d.js toolkit
d.js toolkit2mo ago
- 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!
edocsil
edocsilOP2mo ago
npm ls `-- [email protected] node -v v20.17.0
edocsil
edocsilOP2mo ago
First picture in the OP showed it happening in the second interaction, but it can happen immediately as well
No description
NyR
NyR2mo ago
Okay I can reproduce it. But i suspect the issue is on discord's side. I noticed messageCreate event is being fired for the ephemeral response with only DirectMessages intent event though command was used in a guild. This may indirectly be causing the guildId to be undefined. Idk someone more knowledgeable can shed some more light on this. I haven't looked at the source code. I'm not sure messageCreate for ephemeral is supposed to be fired with only DirectMessages intent. Will have to check with dapi server this looks to be intented behaviour
Syjalo
Syjalo2mo ago
The issue is in GuildChannel.js:68 Sometimes the data have guild_id property, but with value of undefined. Can you create an issue?
edocsil
edocsilOP2mo ago
Yes I can create an issue for it https://github.com/discordjs/discord.js/issues/10495 Not sure if I'm supposed to mark this post as resolved now, but the issue is created. Thanks for the help!
Want results from more Discord servers?
Add your server