【发布时间】:2021-04-02 14:42:34
【问题描述】:
你好,我是编码和处理 Bot 命令的新手,它接受用户输入并将其保存到文本文件中。但是在加载它时会显示“未捕获 TypeError: Cannot read property 'send' of null”
我对各种事物进行了一些更改:
application =collected.array()[0].content; 当 .content 在那里时,它至少会运行几次然后崩溃 Uncaught TypeError: Cannot read property ‘content’ of undefined
let appString = "" + application原来是用toString()函数
fs.appendFile(
./see/letters(${fileSearch}).txt, appString + "\n", function (err) added $fileSearch 因为我认为让很多用户保存到我的本地计算机文件会让人不知所措
我们将不胜感激任何关于这件事的帮助,因为我尝试的每一件事都会让它崩溃,但似乎都是一些 Uncaught TypeError
module.exports = {
name: 'ocean',
description: 'Takes User Input and saves it as Text file letters.txt',
execute(message, args) {
let application = {}
let filter = (message) => !message.author.bot;
let options = {
max: 1,
time: 15000
};
message.member.send("Write something")
.then(dm => {
// After each question, we'll setup a collector on the DM channel
return dm.channel.awaitMessages(filter, options)
})
.then(collected => {
// Convert the collection to an array & get the content from the first element
application = collected.array()[0];
let fileSearch = Math.floor(Math.random() * 11) + 1
let appString = "" + application;
var fs = require('fs')
fs.appendFile(`./see/letters(${fileSearch}).txt`, appString + "\n", function (err){
if (err) {
} else {
}
})
// Ask the next question
console.log(application)
return message.member.send("Got it, It was recieved")
})
}
}
【问题讨论】:
标签: javascript discord discord.js bots