javascript - discord.js V12 - 控制台命令和变量输出显示为未定义
问题描述
所以,我是 JavaScript 新手。我正在制作一个 Discord 机器人,因为它是我目前唯一真正使用 JavaScript 的东西,而且我想学习一些东西。每当我尝试显示类似 id 的内容时,它都会显示未定义。
client.on("channelCreate", function(channel){
console.log(channel.type+` channel, `+channel.name+`, was created by `+`${channel.owner_id}`+` in the category `+channel.parent_id);
});
我想为我的机器人制作一个基本的日志部分,而我才刚刚开始。我希望它像
00:00:00 CREATE > [Text / Voice] Channel was created by [Creator] under category [category]!
我知道确切的格式没有在代码中实现,我在让它变得漂亮之前测试了很多函数。但结果是这样的(使用我现在拥有的代码)
text channel, s, was created by undefined in the category undefined
我很困惑,因为我喜欢细节,所以我想要谁创建它,什么时候,还有类别!那我该怎么做呢?
另外,有没有办法从控制台发送消息和东西?就像我在控制台中输入的一样
[channel or user] > [the message]
#testchannel > Announcing new video or something idk
并将其发送到频道?任何帮助表示赞赏!
编辑:我忘了提到我有 owner_id${var}
格式的部分,因为我正在测试它是否可以使它工作,但我从来没有把它换回来大声笑
解决方案
更改channel.parent.name
会起作用,但没有办法知道谁创建了频道,这是代码 -
client.on("channelCreate", function(channel){
console.log(channel.type+` channel, `+channel.name+`,`+` in the category `+channel.parent.name);
});
推荐阅读
- amazon-web-services - 使用带有嵌套属性的 ScanFilter 扫描 AWS DynamoDB
- c - 谐波级数部分和计算过程中累积的计算误差
- android - W/System.err:java.io.FileNotFoundException
- angular - 未找到“src/assets”文件夹中的 JSON 文件
- flutter - 如何在 Flutter 中的 iOS 和 Android(原生)上显示不同的日期选择器?
- linux - 识别现有文件夹
- python-2.7 - 如何通过 python quickbook api 在发票中更新印度 GST 的“供应地点”和“位置”
- android - 如何在 android >= 8 上打开内容 URI 的 pdf?
- python - Tensorflow 对象检测 API 中的训练和验证准确性
- python - Scipy样条插值:在实际计算之前确定tck中节点向量的数组长度/ B样条系数