How to send a message in a specific channel in "guildMemberRemove" event ? #8780
-
My goal is to send a message in a specific channel when a member leaves the server. I used the method provided by the discord.js documentation : The error is always this: Do you have an explanation of possible errors? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The error you receive means that Now this, in turn, means that either the key is wrong (make sure you pasted the right value) or that the cache simply does not hold the expected channel. Since channels generally arrive on ready with the initial guild payloads and are updated via incoming events, that suggests the cache might just be empty. If not already the case, move the code into some execution scope that runs after the client is ready. In your case "when a member leaves the server" would suggest the If you are retrieving the key from storage (a database/web API), please make sure it is never treated as a number (store as a string, process as a string), as that would truncate the value and corrupt the key. (JavaScript simply cannot deal with numbers as large as Discord ids) |
Beta Was this translation helpful? Give feedback.
The error you receive means that
channel
has the valueundefined
which means the cache-lookup.cache.get(key)
was unsuccessful.This means that at the time this code runs there is no channel with the provided key in the cache.
Now this, in turn, means that either the key is wrong (make sure you pasted the right value) or that the cache simply does not hold the expected channel. Since channels generally arrive on ready with the initial guild payloads and are updated via incoming events, that suggests the cache might just be empty.
If not already the case, move the code into some execution scope that runs after the client is ready. In your case "when a member leaves the server" would sugges…