#Error [CHANNEL_NOT_CACHED] Could not find the channel where this message came from in the cache!
1 messages · Page 1 of 1 (latest)
I'm curious, can you send your client constructor?
And please re-link the code in here.
Yes give me a sec
fetch the channel first so the channel would get cached
<client>.channels.fetch(string)
yes but this would fix it
I want to know why it happens in the first place
not enough memory for caching
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
I see you do interaction.channel.delete() a couple places
Are you sure that isn't triggering before any other code?
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
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
The only event the channel get deleted is when a user do not accept the ToS so by clicking reject or if the channel is manually deleted
Yes one sec
Channel: https://sourceb.in/QOTuJZcRPP
Can you tell me the steps you do to get the error?
It's too much for me to look at 400 lines
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.
Oh, so you delete it yourself mid-way?
Yup
Can you log interaction.channel in each collector when you do this
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.
Just to be sure, I inserted the console.log after every collect[Number].on("collect", m => {
Sure
Every time I answer a question: https://sourceb.in/XP3e9TEtBR
Nope
Okay
I answered the first question then I deleted the channel: https://srcb.in/12MOfcZp7U
The timeout option has been removed from the Message#delete method.
- message.delete(5000)
- message.delete({ timeout: 5000 })
+ setTimeout(() => { message.delete() }, 5000)
Shouldn't be related to the issue but
Oh okay thx
Yup
That doesn't sound intended to me
What if we try a big try/catch, I don't need it to be the best way just that it works
Sure, but that would just be a work-around
The collector should disassemble itself
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)
Can you try doing this? https://stackoverflow.com/help/minimal-reproducible-example
I can try to reproduce this myself, since I'm genuinely unsure why it just errors
It would be perfect if you could, but I don't want to seem too forward 😅
In the meantime I try to rewrite the code in a more readable and minimal way
The point is to minimise the code, so it's easier to diagnose
Yes of course let me do that
But this does sound like a bug to me
The error says that you tried to edit the message in the end event when the channel got deleted
yeah I know that, and I want to "break" the questions process when I delete the channel
You need to check the reason in the end event
Okay so you mean I have to add a check when collect[Number].on("end", collected => {
Second parameter is the reason the collector was ended
I wish the end reasons were documented better tho
And consistent, at least for max => "limit"
Ah I see, I looked at the last one
Okay so let me add the reason to the end event
But there's no edit there since... well it's the last one
You can log it to see what it actually is when you delete the channel
Okay
Basically don’t edit the message for any "*Delete" reasons (channelDelete, guildDelete, threadDelete)
Okay I answered the first question then deleted the channel before answering the second question: https://sourceb.in/6rkmwlQzPp
(What is logged is the reason)
user means collector.stop was called with no parameters
Yes and that's true
channelDelete means the channel was deleted
Okay so basically I need to insert a check for the reason and when is channelDelete is stops(?)
So a return if reason.includes("Delete") is true should work
Okay let me try
if(reason.includes("Delete")) return;
Something like this right?
Yea
Right after the collect end
Inside the end event
before you do anything else in the event
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?
Tried to delete a deleted message
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
Oh sorry, I tried to un the !close command when the bot is asking for an answer to the question
Yup
So I tried if(interaction.message.includes("!")) return;
You can do a .catch() on the message#delete
I would find a way to avoid the error altogether tho
That's better
Esp if you have control over the logic
Agreed
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?
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
Sorry I not explained myself well, I meant right after collect[Number].on("collect", m => {
You have multiple collectors for one command?
Is not a command I'm referring to the questions code
The user has to trigger the questions somehow
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.
You could do this in one collector tho
collect[Number] implies you have multiple collectors for the same session
Yea, you don’t need that
Oh
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
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.
Then don’t process it as an answer if it starts with a prefix
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.
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
okay let me try
If I understood correctly it should be something like this: https://sourceb.in/yHwraZf6ur
It doesn’t look like ur checking for prefix
Also missing the logic for sending the next question if available
I know because I'm trying to understand how to do that
I managed to make it work as I wanted