javascript - 未捕获的类型错误:无法读取 node.js 中未定义的属性“通道”
问题描述
我需要为我的朋友创建一个垃圾邮件命令,这是我的代码:
var msgSplit = message.content.split(" ")
if(message.content.startsWith(prefixe+"spam"))
{
if(message.author.id == '389075094045196328')
{
var message = msgSplit[1]
message.channel.send("1")
}
}
我遇到了这个问题:Uncaught TypeError: Cannot read property 'channel' of undefined
如果我输入这段代码,我不会遇到任何问题:
if(message.content.startsWith(prefixe+"spam"))
{
if(message.author.id == '389075094045196328')
{
message.channel.send("1")
}
}
如果你有想法请告诉我(对不起我的英语不好:/)
解决方案
如果message.content
不包含任何空格,那msgSplit[1]
将是undefined
因为您最终将得到msgSplit
仅包含 1 个元素的数组。
const test = '111'
const splittedTest = test.split(' ')
console.log(splittedTest[0]) // 111
console.log(splittedTest[1]) // undefined
推荐阅读
- c++ - 查找值在文本文件中的出现次数和行数?
- java - 这是使用 HeapSort 的 O(nlogn) 时间复杂度吗
- python - Cronjob 未在 Python 和 Mac 上运行
- scala - 如何添加到您要返回的列表中?
- r - R:来自 .gpx 文件的航向/方向/方位 - tmaptools
- python - 如何从流式 csv 文件创建 multiIndex 数据帧
- javascript - 生产构建中的 Angular 问题,但在本地开发中没有。错误类型错误:无法读取未定义的属性“调用”
- javascript - 自定义 Tcpdf 在同一个文件上签名多个数字pdf
- python - 从图像 numpy 数组中删除 False/True 的 numpy 数组
- vim - 如何只匹配vimregex中的第一个