输入字符串Token触发ERR_INVALID_ARG_TYPE错误及npm警告排查
问题排查:Discord自机器人Token输入后触发无效参数类型错误
相关代码片段
global.FolderPath = path.join(os.homedir(), "data") global.DataPath = path.join(global.FolderPath, "data.json") let Data: {[key: string]: Configuration} = {}; if (fs.existsSync(global.DataPath)) { const fileContent = fs.readFileSync(global.DataPath, "utf-8"); if (typeof fileContent === "string") { try { Data = JSON.parse(fileContent) as {[key: string]: Configuration}; } catch (error) { console.error("Error parsing JSON:", error); } } else { console.error("File content is not a string."); } } else { console.warn(`File does not exist at ${global.DataPath}. Creating a new file.`); } // If the folder doesn't exist, create it and write an empty object to the file if (!fs.existsSync(global.FolderPath)) { fs.mkdirSync(global.FolderPath); fs.writeFileSync(global.DataPath, "{}"); } process.on("unhandledRejection", (error) => { console.error(error); // Assuming log is defined elsewhere log("Unhandled Rejection Found!", "PROMISE.ERROR"); });
运行时错误信息
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined at new NodeError (node:internal/errors:399:5) at Function.from (node:buffer:330:9) at DiscordAuthWebsocket._decryptPayload (C:\Users\V\Downloads\discord-owo-selfbot-main\node_modules\discord.js-selfbot-v13\src\util\RemoteAuth.js:335:28) at DiscordAuthWebsocket._findRealToken (C:\Users\V\Downloads\discord-owo-selfbot-main\node_modules\discord.js-selfbot-v13\src\util\RemoteAuth.js:473:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 'ERR_INVALID_ARG_TYPE' }
问题背景
程序要求输入字符串类型的Token,但输入后出现上述无效参数类型错误,同时收到string-similarity@4.0.4的npm警告,怀疑二者相关,请求协助排查解决。
排查与解决建议
1. 核心:确认Token的有效性与传递链路
错误栈明确指向_decryptPayload方法接收了undefined参数,说明用于解密的核心数据(即Token或关联加密数据)未正确传递:
- 检查输入的Token是否为非空字符串,排除输入时的空值、空格或读取失败问题
- 跟踪Token从输入到传入
DiscordAuthWebsocket模块的全流程,确保没有在中间环节被赋值为undefined
2. 处理string-similarity依赖警告
string-similarity@4.0.4版本较旧,可能存在依赖兼容问题,建议:
- 执行更新命令到最新版本:
npm update string-similarity
- 若更新无效,尝试卸载重装:
npm uninstall string-similarity npm install string-similarity
3. 校验配置文件读写逻辑
你提供的代码负责读写配置文件,需确认:
data.json中存储的Token字段是否存在且为字符串类型,避免JSON解析后出现undefined- 写入配置文件时,确保Token值未被意外覆盖或转换为非字符串类型
4. 临时规避:绕开RemoteAuth流程
如果错误源于RemoteAuth模块的加密逻辑,可尝试直接用Token初始化客户端:
const { Client } = require('discord.js-selfbot-v13'); const client = new Client({ token: "你的Token字符串" }); client.login();
内容的提问来源于stack exchange,提问作者Backup Up
相关产品推荐
相关产品推荐

