interaction.channel = null

Sometimes interaction.channel = null. This is often fixed by restarting the bot. But I don't want to restart the bot every 24 hours. It's a command interaction that was executed in a guild. The bot is in this guild and the guild is cached.
// It returned "true" anyways
if (!interaction.inCachedGuild()) await client.guilds.fetch(client.config.guild_id);
// It returned "true" anyways
if (!interaction.inCachedGuild()) await client.guilds.fetch(client.config.guild_id);
Along with that I fetch the channel if I am receiveing a chanel partial
const channel = interaction.channel == null ? await interaction.channel.fetch() : interaction.channel;
const channel = interaction.channel == null ? await interaction.channel.fetch() : interaction.channel;
But I am still getting this error
| [ERR] | DiscordAPIError[10003]: Unknown Channel
/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:640
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
| [ERR] | DiscordAPIError[10003]: Unknown Channel
/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:640
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
18 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Syjalo
Syjalo2y ago
This should throw Cannot read properties of null
Syjalo
Syjalo2y ago
Could you show the full error?
Zeroknights
ZeroknightsOP2y ago
I cannot show you the full stack trace because I am dumb and I just logged the error name without the stack trace. However another error occured when it proceed and tried to send an embed
DiscordAPIError[10003]: Unknown Channel
at handleErrors (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:1021:23)
at async SequentialHandler.queueRequest (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:862:14)
at async REST.request (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async TextChannel.send (/root/DiscordBot/Multibot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:157:15) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
color: 15269888,
description: '``❌`` An **error** occured while executing function ``ticketClose``'
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: { message: 'Unknown Channel', code: 10003 },
code: 10003,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1115061483353673738/messages'
}
DiscordAPIError[10003]: Unknown Channel
at handleErrors (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:1021:23)
at async SequentialHandler.queueRequest (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:862:14)
at async REST.request (/root/DiscordBot/Multibot/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async TextChannel.send (/root/DiscordBot/Multibot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:157:15) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
color: 15269888,
description: '``❌`` An **error** occured while executing function ``ticketClose``'
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: { message: 'Unknown Channel', code: 10003 },
code: 10003,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1115061483353673738/messages'
}
This is probably the same error anyways. So is interaction.channel even null 😂
treble/luna
treble/luna2y ago
the channel id gets passed into the url so your channel isnt null, its just not a valid channel could be a message id, role id, user id etc
Syjalo
Syjalo2y ago
It looks like the channel already got deleted when the bot sent the message
Zeroknights
ZeroknightsOP2y ago
it doesn't get deleted because it errors 😂 but I gotta correct myself, this is not a command interaction. It's a button interaction
Syjalo
Syjalo2y ago
At least there's already no channel with that id
Zeroknights
ZeroknightsOP2y ago
Sometimes it works after restarting the bot this doesn't make sence and overall it errors 1 out of 10 button interactions
Syjalo
Syjalo2y ago
Could you show your ticketClose code?
Zeroknights
ZeroknightsOP2y ago
sure
d.js docs
d.js docs2y ago
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.
Zeroknights
ZeroknightsOP2y ago
Gist
cd_close.js
GitHub Gist: instantly share code, notes, and snippets.
Zeroknights
ZeroknightsOP2y ago
const splitValue = interaction.customId.split(':');
switch(splitValue[3]) {
case 'close': {
await cd_close(interaction, this.client, 'No reason provided');
break;
}
...
const splitValue = interaction.customId.split(':');
switch(splitValue[3]) {
case 'close': {
await cd_close(interaction, this.client, 'No reason provided');
break;
}
...
Syjalo
Syjalo2y ago
In line 35 you should log the error to console, not send it as an embed, it's not an embed.
Zeroknights
ZeroknightsOP2y ago
it's a custom function it returns the embed and logs the error
if (!interaction.inCachedGuild()) await client.guilds.fetch(client.config.guild_id);
const channel = interaction.channel == null ? await interaction.channel.fetch() : interaction.channel;
if (!interaction.inCachedGuild()) await client.guilds.fetch(client.config.guild_id);
const channel = interaction.channel == null ? await interaction.channel.fetch() : interaction.channel;
I have been told that a possibility is that the guild is not cached, I had no idea to fix it so I added that (being aware of that this probably doesn't work that way) So originally these 2 lines would be gone I see but I am still wondering how this can happen but none of them are the reasons, it's a bot account 100% and the command was executed in a guild where the bot is a memberof let me double check nope
d.js docs
d.js docs2y ago
Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
client
.on("debug", console.log)
.on("warn", console.log)
• Note: if you initialize your Client as bot or other identifiers you need to use these instead of client • If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
Zeroknights
ZeroknightsOP2y ago
that's what I am thinking I can't reproduce this issue but someone else who has access to the bot he's using node v20, might this be an issue here? It is my bot, but another user who's using my bot told me that this isn't working. So I got access to his hosting provider to get all required information (he got the files) bot code nope he created his own bot account because he gave me perms You can trust me at that point I am not retarded holy
Want results from more Discord servers?
Add your server