client.channels.cache.get(<id>) 在不和谐中显示 unidenfied.js我已经尝试了许多解决方案


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);

输出: -

Anonymous HELPER 😶 #4205  logged in 
undefined

我已经检查了其他解决方案

  1. https://discordjs.guide/popular-topics/faq.html how-do-i-set-both-status-and-activity-in-one-go
  2. command .js: TypeError: client.channels.get is not a function
  3. client.channels.cache.get('id')返回空Map
  4. 用Discord.js发送消息
  5. 无法使用client.channels.cache.get(")

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)

版本——

"discord.js": "^13.6.0",
"dotenv": "^16.0.0"
"node.js": "^16.14.2"

客户端当时还没有准备好,所以缓存是空的。把它放到ready事件中

client.on('ready',() => {
const channel = client.channels.cache.get("967808235048423484");
console.log(`${client.user.tag}  logged in`);
console.log(channel);
});

最新更新