Con*_*nta 11 javascript node.js discord.js
我正在编写一个 Discord 机器人。当我尝试运行节点时,我在CMD中收到此消息窗口中看到以下内容:
\n\n\nC:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\discord.js\\src\\client\\Client.js:544\n抛出新的 TypeError(\'CLIENT_MISSING_INTENTS\');
\n
\n^类型错误 [CLIENT_MISSING_INTENTS]:必须为客户端提供
\n
\n有效意图。
\nat Client._validateOptions (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\\xe2\x86\x90[4mdiscord.js\xe2\x86\x90[24m\\src\\client\ \Client.js:544:13)
\nat 新客户端 (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\\xe2\x86\x90[4mdiscord.js\xe2\x86\x90[ 24m\\src\\client\\Client.js:73:10)
\nat 对象。(C:\\Users\\utente\\Desktop\\bouncerBot\\main.js:2:16) \xe2\x86\x90[90m at
\nModule._compile (internal/modules/cjs/loader.js:1072) :14)\xe2\x86\x90[39m \xe2\x86\x90[90m
\nat Object.Module._extensions..js
\n(内部/模块/cjs/loader.js:1101:10)\xe2\x86 \x90[39m \xe2\x86\x90[90m 在 Module.load
\n(内部/模块/cjs/loader.js:937:32)\xe2\x86\x90[39m \xe2\x86\x90[90m 在
\nFunction.Module._load (内部/modules/cjs/loader.js:778:12)\xe2\x86\x90[39m
\n\xe2\x86\x90[90m 在 Function.executeUserEntryPoint [as runMain]
\n(内部/模块/run_main.js:76:12)\xe2\x86\x90[39m \xe2\x86\x90[90m 在
\ninternal/main/run_main_module.js:17:47\xe2\x86\x90[39m {
\n[\xe2\x86\x90[32mSymbol(代码)\xe2\x86\x90[39m]: \xe2\x86\x90[32m\'CLIENT_MISSING_INTENTS\'\xe2\x86\x90[39m } \\C:\\Users\\utente\\Desktop\\bouncerBot>node 。
\n
\nC:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\discord.js\\src\\client\\Client.js:544
\n抛出新的 TypeError(\'CLIENT_MISSING_INTENTS\');
\n^ \\类型错误 [CLIENT_MISSING_INTENTS]:必须为客户端提供
\n
\n有效意图。
\nat Client._validateOptions (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\\xe2\x86\x90[4mdiscord.js\xe2\x86\x90[24m\\src\\client\ \Client.js:544:13)
\nat 新客户端 (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\\xe2\x86\x90[4mdiscord.js\xe2\x86\x90[ 24m\\src\\client\\Client.js:73:10)
\nat 对象。(C:\\Users\\utente\\Desktop\\bouncerBot\\main.js:3:16) \xe2\x86\x90[90m at
\nModule._compile (internal/modules/cjs/loader.js:1072) :14)\xe2\x86\x90[39m \xe2\x86\x90[90m
\nat Object.Module._extensions..js
\n(内部/模块/cjs/loader.js:1101:10)\xe2\x86 \x90[39m \xe2\x86\x90[90m 在 Module.load
\n(内部/模块/cjs/loader.js:937:32)\xe2\x86\x90[39m \xe2\x86\x90[90m 在
\nFunction.Module._load (内部/modules/cjs/loader.js:778:12)\xe2\x86\x90[39m
\n\xe2\x86\x90[90m 在 Function.executeUserEntryPoint [as runMain]
\n(内部/模块/run_main.js:76:12)\xe2\x86\x90[39m \xe2\x86\x90[90m 在
\ninternal/main/run_main_module.js:17:47\xe2\x86\x90[39m {
\n[\xe2\x86\x90[32mSymbol(代码)\xe2\x86\x90[39m]: \xe2\x86\x90[32m\'CLIENT_MISSING_INTENTS\'\xe2\x86\x90[39m
我尝试在网上搜索解决方案,但没有找到任何结果。我还在机器人设置中激活了以下药水,但没有任何变化:
\n\n这是我的代码,即使它不是错误的原因:
\nconst Discord = require(\'discord.js\');\nconst fs = require(\'fs\');\nconst client = new Discord.Client();\n\nlet rawdata = fs.readFileSync(\'config.json\');\nlet config = JSON.parse(rawdata);\n\nconst TOKEN = config.botToken\nconst prefix = config.prefix\n\nclient.login(TOKEN)\nclient.on(\'message\', message => {\n if (!message.content.startsWith(prefix) || message.author.bot)\n return;\n const args = message.content.slice(prefix.lenght).split(/ +/)\n const command = args[1].toLowerCase()\n console.log(args)\n // Command test!\n})\n\nclient.once(\'ready\', () => {\n console.log("Discord bot online")\n});\nRun Code Online (Sandbox Code Playgroud)\n{\n "botToken":"",\n "prefix":"!pgc"\n}\nRun Code Online (Sandbox Code Playgroud)\n我还尝试更新代码如下:
\nconst Discord = require(\'discord.js\');\nconst fs = require(\'fs\');\n\nconst { Client, Intents } = require(\'discord.js\');\n\nconst client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });\n\nlet rawdata = fs.readFileSync(\'config.json\');\nlet config = JSON.parse(rawdata);\n\nconst TOKEN = config.botToken\nconst prefix = config.prefix\n\nclient.on(\'message\', message => {\n if (!message.content.startsWith(prefix) || message.author.bot)\n return;\n const args = message.content.slice(prefix.lenght).split(/ +/)\n const command = args[1].toLowerCase()\n console.log(args)\n // Command test!\n})\n\nclient.once(\'ready\', () => {\n console.log("Discord bot online")\n});\n\nclient.login(TOKEN)\nRun Code Online (Sandbox Code Playgroud)\n但我仍然收到错误:
\n\n\n(节点:12216)UnhandledPromiseRejectionWarning:ReferenceError:
\n
\ nAbortController未定义
\ nat RequestHandler.execute(C:\\ Users \\ utente \\ Desktop \\ bouncerBot \\ node_modules \\discord.js \\ src \\rest \\ RequestHandler.js:172:15)
\nat RequestHandler.execute (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:176: 19)
\nat RequestHandler.push (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:50:25)
\nat 异步 WebSocketManager .connect (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\discord.js\\src\\client\\websocket\\WebSocketManager.js:128:9)
\nat 异步 Client.login (C:\\Users\\utente\\Desktop\\bouncerBot\\node_modules\\discord.js\\src\\client\\Client.js:245:7)
\n(用于node --trace-warnings ...显示警告所在位置\ ncreated) (节点:12216) UnhandledPromiseRejectionWarning: 未处理\npromise 拒绝。此错误的根源可能是在没有 catch 块的情况下抛出\n异步函数,或者是拒绝\n未使用 .catch() 处理的承诺。要在\n未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志\n--unhandled-rejections=strict(请参阅\n https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。\n(拒绝 ID:2)(节点:12216) ) [DEP0018] DeprecationWarning: 未处理的\n承诺拒绝已被弃用。将来,未处理的承诺拒绝将\n以非零退出代码终止 Node.js 进程。
wol*_*e00 34
首先,永远不要显示你的机器人的令牌,或者稍后尝试更改它。
其次:
尝试使用这个。由于discord.js的新版本(例如版本^13.0),您必须指定客户端意图:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
Run Code Online (Sandbox Code Playgroud)
显然,放在client.login(TOKEN)最底部。
有关新版本 Discord.js 所需的更多更新,请参阅新增功能。
| 归档时间: |
|
| 查看次数: |
99095 次 |
| 最近记录: |