简体   繁体   English

如何修复“无法读取未定义的属性'长度'”和 Args 输入在我的扫雷命令中不起作用 - Discord.js

[英]How do I fix “Cannot read property 'length' of undefined” and Args Input not working in my Minesweeper Command - Discord.js

I am making a Minesweeper command using discord.js.我正在使用 discord.js 制作扫雷命令。 It is using args to collect the user's inputs for the Minesweeper board.它使用 args 来收集用户对扫雷板的输入。 (ie a3, a3f [f for flag]). (即 a3, a3f [f 代表标志])。 However, the command runs perfect, it shows the board with letter and numbers on the top and side.但是,该命令运行完美,它在顶部和侧面显示带有字母和数字的板。 The main issue I am having is the command will not take those response arg inputs that I put in. This is how the user will be able to play.我遇到的主要问题是命令不会接受我输入的那些响应 arg 输入。这就是用户将能够玩的方式。

After the round ends (without any input) It throws the error Cannot read property 'length' of undefined .回合结束后(没有任何输入)它抛出错误Cannot read property 'length' of undefined This is somewhat referred to these lines of code.这有点提到这些代码行。

const filter = msgs => {
    const param = msgs.content.toLowerCase().split(" ");
    return param.length === 2 && alphabet.includes(param[0]) && parseInt(param[1], 10) < 7 && !answered.includes(param.join("")) && msgs.author.id === msg.author.id;
};

param[0] = alphabet.includes[param[0]];
param[1] = parseInt(param[1], 10) - 1;
if (board[param[1]][param[0]] === "💣") {
    for (let i = 0; i < board.length; i++) {
        for (let j = 0; j < board[i].length; i++) {
            if (board[i][j] === "💣") showboard[i][j] = "💣";
        }
    }

I believe this is what is causing the issue of my minesweeper command.我相信这就是导致我的扫雷命令问题的原因。 I am not 100% certain but I think I might be able to fix it by defining the params to args[0]我不是 100% 确定,但我认为我可以通过将参数定义为args[0]来修复它

I have the full code here for the command: https://natebot-haste.glitch.me/lusarovisa.js我在这里有命令的完整代码: https://natebot-haste.glitch.me/lusarovisa.js

I am honestly not too sure what to do from this point, I've attempted changing the param definition and since code seems perfect, I might as well ask here.老实说,从这一点开始,我不太确定该怎么做,我尝试更改参数定义,并且由于代码看起来很完美,我不妨在这里问一下。

Since it seems to be a problem with Params being either null or undefined how about doing a check like this?由于 Params 似乎是 null 或未定义的问题,那么进行这样的检查怎么样?

 const filter = msgs => {
        const param = msgs.content.toLowerCase().split("");
        if(param && param.length === 2) {
            return alphabet.includes(param[0]) && parseInt(param[1], 10) < 7 && !answered.includes(param.join("")) && msgs.author.id === msg.author.id;
        }
        else {
            return false
        }
      };
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决discord.js中的“无法读取未定义的属性&#39;反应&#39;” - How to fix “Cannot read property 'react' of undefined” in discord.js Discord.js | 当我尝试运行我的 Discord.js 命令时,它会吐出错误“无法读取未定义的属性'执行'” - Discord.js | When I attempt to run my Discord.js command, it will spit out an error “Cannot read property 'execute' of undefined” Discord.js:无法读取Null的属性“名称”-我该如何解决? - Discord.js: Cannot Read Property “Name” of Null - How do I fix this? 无法读取未定义的 discord.js 警告命令的属性“发送” - Cannot read property 'send' of undefined discord.js warn command 如何解决:“TypeError:无法读取discord.js中未定义的属性&#39;标签&#39;错误 - How to fix: “TypeError: Cannot read property 'tag' of undefined” error in discord.js 如何修复“TypeError:无法读取未定义的属性 'toString'” | discord.js - How to fix “TypeError: Cannot read property 'toString' of undefined” | discord.js 我试图运行命令 Discord.js 但出现错误“TypeError:无法读取未定义的属性'get'” - i m trying to run a command Discord.js but error appear “TypeError: Cannot read property 'get' of undefined” Discord 机器人 | discord.js | TypeError:无法读取未定义的属性“长度” - Discord Bot | discord.js | TypeError: Cannot read property 'length' of undefined (DISCORD.JS) 如何修复我的 discord“cmds”命令? - (DISCORD.JS) how do i fix my discord "cmds" command? 我用 discord.js 编写了一个 discord 机器人,并且我的命令处理程序出现错误“无法读取未定义的属性'set'” - I code a discord bot with discord.js and i have the error “Cannot read property 'set' of undefined” with my commnd handler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM