#Error [CHANNEL_NOT_CACHED] Could not find the channel where this message came from in the cache!

1 messages · Page 1 of 1 (latest)

violet jackal
#

I'm curious, can you send your client constructor?

#

And please re-link the code in here.

stray breach
#

Yes give me a sec

cold lagoon
#

fetch the channel first so the channel would get cached

#

<client>.channels.fetch(string)

violet jackal
#

It's not a common error

#

It doesn't "just happen" to most people

cold lagoon
#

yes but this would fix it

violet jackal
#

I want to know why it happens in the first place

cold lagoon
#

not enough memory for caching

stray breach
#

So basically I'm trying to make a Commissions Bot, when a user opens a ticket (so a channel is created) the bot send the first question and collect the answer and do that for 5 times. This is the entire interactionCreate code: https://sourceb.in/ZBNjsVEk5G

#

Line 104 is where the questions start

violet jackal
#

I see you do interaction.channel.delete() a couple places

#

Are you sure that isn't triggering before any other code?

stray breach
#

Yup, the error is triggered when I try to delete the channel where a question is asked by the bot

#

Also the interaction.channel.delete(); you see refer to other buttons

violet jackal
#

Yes, but it still might happen before the other ones

#

Just not in the same "execution" if that makes sense

#

can you log channel?

#

What might be happening is they're accepting first, then deleting the channel whilst collecting their answers(?)

#

But the collectors should disassemble themselves for that

stray breach
stray breach
violet jackal
#

It's too much for me to look at 400 lines

stray breach
# violet jackal Can you tell me the steps you do to get the error?

Essentially, the user clicks a button to open a ticket then the channel is created, in the channel the message is sent to accept the ToS, if they rejected the channel is deleted, instead if they accept the bot sends the first question, the user answers and the bot collects the answer (it does this for 5 times since there are 5 questions), the problem is when I delete the channel manually.

violet jackal
#

Oh, so you delete it yourself mid-way?

stray breach
#

Yup

violet jackal
#

Can you log interaction.channel in each collector when you do this

stray breach
#

Yes of course

#

Give me a sec

violet jackal
#

I cannot think of any neat way to handle that really.

#

My current though is a giant try...catch but... yeah that might not be the best.

stray breach
#

Just to be sure, I inserted the console.log after every collect[Number].on("collect", m => {

violet jackal
#

Sure

stray breach
violet jackal
#

Did you delete the channel mid-way?

#

If not, try doing that

stray breach
#

Nope

#

Okay

violet jackal
#

Hmm

#

By the way

still oliveBOT
#

The timeout option has been removed from the Message#delete method.

- message.delete(5000)
- message.delete({ timeout: 5000 })
+ setTimeout(() => { message.delete() }, 5000)
violet jackal
#

Shouldn't be related to the issue but

stray breach
#

Oh okay thx

violet jackal
#

Hmm

#

I don't get this tbh

#

Does it error right after you delete the channel?

stray breach
#

Yup

violet jackal
#

That doesn't sound intended to me

stray breach
#

What if we try a big try/catch, I don't need it to be the best way just that it works

violet jackal
#

Sure, but that would just be a work-around

#

The collector should disassemble itself

stray breach
#

Umm, what if instead of fixing the problem, we try to rewrite the code according to what I would like to happen (of course if you have time and if you especially want)

violet jackal
#

I can try to reproduce this myself, since I'm genuinely unsure why it just errors

stray breach
stray breach
violet jackal
#

The point is to minimise the code, so it's easier to diagnose

stray breach
#

Yes of course let me do that

violet jackal
#

But this does sound like a bug to me

stray breach
#

Oh

#

I mean there are other bots that does this thing (of course is other ways)

junior mauve
#

The error says that you tried to edit the message in the end event when the channel got deleted

stray breach
junior mauve
#

You need to check the reason in the end event

stray breach
#

Okay so you mean I have to add a check when collect[Number].on("end", collected => {

junior mauve
#

Second parameter is the reason the collector was ended

violet jackal
#

.on("end", (collected, reason) => ..

#

I didn't see that 👀

junior mauve
#

I wish the end reasons were documented better tho

#

And consistent, at least for max => "limit"

violet jackal
#

Ah I see, I looked at the last one

stray breach
#

Okay so let me add the reason to the end event

violet jackal
#

But there's no edit there since... well it's the last one

violet jackal
stray breach
#

Okay

junior mauve
#

Basically don’t edit the message for any "*Delete" reasons (channelDelete, guildDelete, threadDelete)

stray breach
#

(What is logged is the reason)

junior mauve
#

user means collector.stop was called with no parameters

stray breach
#

Yes and that's true

junior mauve
#

channelDelete means the channel was deleted

stray breach
#

Okay so basically I need to insert a check for the reason and when is channelDelete is stops(?)

violet jackal
#

So a return if reason.includes("Delete") is true should work

stray breach
#

if(reason.includes("Delete")) return;

#

Something like this right?

junior mauve
#

Yea

stray breach
#

Right after the collect end

junior mauve
#

Inside the end event

violet jackal
#

before you do anything else in the event

stray breach
#

Yeah I meant:

collectOne.on("end", (collected, reason) => {
  if(reason.includes("Delete")) return;
  console.log(reason)
....
#

It worked, I tried to answer the first question and it registered "user" in the console and then before answering the second question I tried to delete the channel and the error was not throwed.

#

You guys have been really kind in helping me understand how to solve this problem, really thank you so much 🙂
One last thing, to delete the ticket channels I also created a !close command, when I try to execute it in the middle of the questions the bot returns this error: https://sourceb.in/k1JkFiD9Fp

According to you it is enough to insert an if that checks if the message contains the prefix at the beginning of each collector?

junior mauve
#

Tried to delete a deleted message

stray breach
#

Yes, I know what the error means and I thought that making an if statement at the beginning of each collector could solve this problem, right?

#

Something like if message contains the prefix return

junior mauve
#

Idk where ur deleting it

#

If it’s in the collect event, await it

stray breach
#

Oh sorry, I tried to un the !close command when the bot is asking for an answer to the question

stray breach
#

So I tried if(interaction.message.includes("!")) return;

violet jackal
#

You can do a .catch() on the message#delete

junior mauve
#

I would find a way to avoid the error altogether tho

violet jackal
#

That's better

junior mauve
#

Esp if you have control over the logic

violet jackal
#

Agreed

stray breach
#

So essentially, let me know if you agree with my reasoning: when the collector starts, before doing anything else it checks if the message contains the prefix or if the reason contains Delete, if this is true then return. Right?

junior mauve
#

I don’t understand how you would check the reason if the collector just started

#

Or how you would check the message if it just started

#

If it just started, nothing happened yet

stray breach
#

Sorry I not explained myself well, I meant right after collect[Number].on("collect", m => {

junior mauve
#

You have multiple collectors for one command?

stray breach
#

Is not a command I'm referring to the questions code

junior mauve
#

The user has to trigger the questions somehow

stray breach
#

Let me explain again because I think we didn't understand each other.

#

When the bot sends a question and instead of answering the question I delete the channel manually it gives an error, now that we fixed this problem, I have a command (!close) that is used to delete the channel, when I try to use this command after the bot has asked me a question it returns an error.
To solve this problem I thought to insert an if statement when the bot collects the answer to the question and if the answer contains the command prefix then the bot skips it.

junior mauve
#

You could do this in one collector tho

#

collect[Number] implies you have multiple collectors for the same session

stray breach
#

Yup that's true

#

One for each question/answer

junior mauve
#

Yea, you don’t need that

stray breach
#

Oh

junior mauve
#

One collector can do it all

#

Have an array of questions and another array to store the answers

#

Also store a number that starts from 0 to represent the index of the current question

stray breach
#

Okay I got your reasoning

#

But in any case I didn't understand if what I said about skipping the commands in the answers is correct?
Because I would make that if the message in response to the question contains the command prefix then the bot doesn't count it.

junior mauve
#

Then don’t process it as an answer if it starts with a prefix

stray breach
#

I would use this method to do so: if(interaction.message.content.includes("!")) return;
But doing this would cause the error to recur, and if successful the bot would disregard the message after the command.

junior mauve
#

Check if it’s !close first or whatever you want to stop the questions

#

Then check for prefix

#

And if none of the above applies, then process as an answer

stray breach
#

okay let me try

junior mauve
#

It doesn’t look like ur checking for prefix

#

Also missing the logic for sending the next question if available

stray breach
stray breach
#

I managed to make it work as I wanted