'client.channels.cache.get(<id>) showing unidenfied in discord.js i already tried many solution
require('dotenv').config();
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const channel = client.channels.cache.get("967808235048423484");
client.on('ready',() => {
console.log(`${client.user.tag} logged in`);
console.log(channel);
});
client.login(process.env.DISCORDJS_BOT_TOKEN);
output:-
Anonymous HELPER 😶 #4205 logged in
undefined
I already check other solution
- https://discordjs.guide/popular-topics/faq.html#how-do-i-set-both-status-and-activity-in-one-go
- Discord.js : TypeError: client.channels.get is not a function
- client.channels.cache.get('id') returns empty Map
- Send a message with Discord.js
- unable to use client.channels.cache.get(")
like
const channel = await client.channels.fetch(CHANNEL_ID)
error:-SyntaxError: await is only valid in async functions and the top level bodies of modules
const channel = client.channels.fetch(channelID)
version -
"discord.js": "^13.6.0",
"dotenv": "^16.0.0"
"node.js": "^16.14.2"
Solution 1:[1]
The client is not ready at the time, so the cache is empty. Put that in the ready event.
client.on('ready',() => {
const channel = client.channels.cache.get("967808235048423484");
console.log(`${client.user.tag} logged in`);
console.log(channel);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MrMythical |
