【发布时间】:2020-12-05 22:12:17
【问题描述】:
我正在尝试通过 discord.js 发送消息,但出现以下错误:(node:10328) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
这是我的代码:
// Init
const Discord = require("discord.js");
const bot = new Discord.Client();
const channel = bot.users.cache.get('4257');
// Vars
// Code
bot.on("ready", () => {
console.log("The Bot is ready!");
channel.send("Test");
});
// Login
bot.login(" "); // I will hide this.
怎么了?是通道变量上的 id 吗?我只是输入了我的机器人的 id,因为我不知道该输入什么。
起初我在“文本权限”下给了它所有权限,但我也尝试给他管理员权限。它仍然没有工作。我做错了什么?
【问题讨论】:
-
问题出在
const channel = bot.users.cache.get('4257');行中,似乎返回未定义。 -
是的,但是为什么呢?我的语法不正确吗?
-
您很可能需要深入研究文档,看看您是否正确使用了这些功能。
标签: node.js discord discord.js