【发布时间】:2021-04-14 22:10:36
【问题描述】:
我一直在尝试使用 channelId 向服务器中的特定文本通道发送消息,但我最终得到了错误:
TypeError: Cannot read property 'get' of undefined
at Object.<anonymous>
使用时
const channel = bot.channels.cache.get('711580200315650078');
这是我的全部代码:
require('dotenv').config();
const Discord = require('discord.js');
const bot = new Discord.Client();
const TOKEN = process.env.TOKEN;
bot.login(TOKEN);
bot.on('ready', () => {
console.info(`Logged in as ${bot.user.tag}!`);
const channel = bot.channels.cache.get('711580200315650078');
channel.send('hello');
});
【问题讨论】:
-
你使用的是哪个版本的 Discord JS?
-
@Jakye 谢谢。这确实是问题所在。
标签: node.js discord discord.js bots typeerror