Javascript Discord.js命令时崩溃;未捕获类型错误“;

Javascript Discord.js命令时崩溃;未捕获类型错误“;,javascript,discord,discord.js,bots,Javascript,Discord,Discord.js,Bots,你好,我是新来的一个机器人命令编码和工作,它接受用户输入并保存到一个文本文件。但在加载时,它会声明“UncaughtTypeError:无法读取null的“send”属性” 我在各种事情上做了一些改变: application=collected.array()[0].content 当.content存在时,它至少会运行几次,然后崩溃,出现未捕获的TypeError:无法读取未定义的属性“content” 让appString=”“+应用程序最初使用的是toString()函数 fs.appe

你好,我是新来的一个机器人命令编码和工作,它接受用户输入并保存到一个文本文件。但在加载时,它会声明“UncaughtTypeError:无法读取null的“send”属性”

我在各种事情上做了一些改变:

application=collected.array()[0].content 当.content存在时,它至少会运行几次,然后崩溃,出现未捕获的TypeError:无法读取未定义的属性“content”

让appString=”“+应用程序最初使用的是toString()函数

fs.appendFile(
/see/letters(${fileSearch}).txt
,appString+“\n”,function(err)添加了$fileSearch,因为我认为必须让许多用户保存到我的本地计算机文件中,这会让它无法承受

在这件事上的任何帮助都将不胜感激,因为我尝试的每一件事都会使它不断崩溃,但似乎都是一些未预料到的错误

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")
        
      })
    }
  }
早上好

我用您给定的代码进行了一些测试,并做了一些更改

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].content;
            let fileSearch = Math.floor(Math.random() * 11) + 1
            let appString = "";
            appString += application;
            var fs = require('fs')
            fs.appendFile(`./see/letters(${fileSearch}).txt`, appString + "\n", function (err) {
                if (err) {
                    console.log(err);
                }
            })
            // Ask the next question
            console.log(application)
            return message.member.send("Got it, It was recieved")
        })
 }
}
首先我想说的是,
application=collected.array()[0].content;
对我来说非常好,每次我都使用它

无论如何,我将
让appString=”“+应用程序;
更改为

  let appString = "";
  appString += application;
它创建了一个变量
appString
,这是一个字符串,因为我们用
初始化了它
。在第二行中,我们用从
应用程序
获取的内容填充当前空字符串。您也可以这样显示它:
appString=appString+application
。这是因为
appString
为空,并将
application
的值输入空字符串中。现在该字符串不是empty不再包含,并且包含来自
应用程序
的内容。这是填充字符串的常用方法

我还更改了你的if-else语句

fs.appendFile(`./see/letters(${fileSearch}).txt`, appString + "\n", function (err){
      if (err) {

      } else {

      }
    })
进入

因为你有if-else,但是什么也没做。现在如果有错误,它会在你的控制台上打印出来

我希望这是可以理解的,并且有助于解决您的问题。

早上好

我用您给定的代码进行了一些测试,并做了一些更改

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].content;
            let fileSearch = Math.floor(Math.random() * 11) + 1
            let appString = "";
            appString += application;
            var fs = require('fs')
            fs.appendFile(`./see/letters(${fileSearch}).txt`, appString + "\n", function (err) {
                if (err) {
                    console.log(err);
                }
            })
            // Ask the next question
            console.log(application)
            return message.member.send("Got it, It was recieved")
        })
 }
}
首先我想说的是,
application=collected.array()[0].content;
对我来说非常好,每次我都使用它

无论如何,我将
让appString=”“+应用程序;
更改为

  let appString = "";
  appString += application;
它创建了一个变量
appString
,这是一个字符串,因为我们用
初始化了它
。在第二行中,我们用从
应用程序
获取的内容填充当前空字符串。您也可以这样显示它:
appString=appString+application
。这是因为
appString
为空,并将
application
的值输入空字符串中。现在该字符串不是empty不再包含,并且包含来自
应用程序
的内容。这是填充字符串的常用方法

我还更改了你的if-else语句

fs.appendFile(`./see/letters(${fileSearch}).txt`, appString + "\n", function (err){
      if (err) {

      } else {

      }
    })
进入

因为你有if-else,但是什么也没做。现在如果有错误,它会在你的控制台上打印出来

我希望这是可以理解的,并有助于解决您的问题