从 github 获取此代码,尝试运行它并抛出此错误,据我所知,错误在 index.js 中,我在此处提供了 index.js 代码 [重复]
Posted
技术标签:
【中文标题】从 github 获取此代码,尝试运行它并抛出此错误,据我所知,错误在 index.js 中,我在此处提供了 index.js 代码 [重复]【英文标题】:Got this code off github, Tried to run it and threw this error, From what i could see, the error was in index.js and i provided the index.js code here [duplicate] 【发布时间】:2021-12-04 23:32:20 【问题描述】:The Error:
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\User\Desktop\pnp music\node_modules\discord.js\src\client\Client.js:544:13)
at new Client (C:\Users\User\Desktop\pnp music\node_modules\discord.js\src\client\Client.js:73:10)
at Object.<anonymous> (C:\Users\User\Desktop\pnp music\index.js:8:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
我的代码:(index.js)
//Importing all needed Commands
const Discord = require("discord.js"); //this is the official discord.js wrapper for the Discord Api, which we use!
const colors = require("colors"); //this Package is used, to change the colors of our Console! (optional and doesnt effect performance)
const Enmap = require("enmap"); //this package is our Database! We will use it to save the data for ever!
const fs = require("fs"); //this package is for reading files and getting their inputs
//Creating the Discord.js Client for This Bot with some default settings ;) and with partials, so you can fetch OLD messages
const client = new Discord.Client(
fetchAllMembers: false,
restTimeOffset: 0,
shards: "auto",
restWsBridgetimeout: 100,
disableEveryone: true,
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
);
require('events').EventEmitter.defaultMaxListeners = 100;
process.setMaxListeners(100);
//Loading files, with the client variable like Command Handler, Event Handler, ...
["clientvariables", "command", "events", "erelahandler", "requestreacts"].forEach(handler =>
require(`./handlers/$handler`)(client);
);
//Each Database gets a own file and folder which is pretty handy!
client.premium = new Enmap( name: "premium", dataDir: "./databases/premium" )
client.stats = new Enmap( name: "stats", dataDir: "./databases/stats" )
client.settings = new Enmap( name: "setups", dataDir: "./databases/settings" )
client.setups = new Enmap( name: "setups", dataDir: "./databases/setups" )
client.queuesaves = new Enmap( name: "queuesaves", dataDir: "./databases/queuesaves", ensureProps: false)
client.modActions = new Enmap( name: 'actions', dataDir: "./databases/warns" );
client.userProfiles = new Enmap( name: 'userProfiles', dataDir: "./databases/warns" );
//login into the bot
client.login(require("./botconfig/config.json").token);
【问题讨论】:
这能回答你的问题吗? Why does the client in discord have an error that outputs: TypeError: [CLIENT_MISSING_INTENTS] in node.js? 【参考方案1】:Discord API 已更新为要求机器人声明其Intents 以便接收某些事件,这可以在创建新Client()
时传递的表中的intents
键中定义。
这应该按预期工作:
const Discord = require("discord.js"); //this is the official discord.js wrapper for the Discord Api, which we use!
const colors = require("colors"); //this Package is used, to change the colors of our Console! (optional and doesnt effect performance)
const Enmap = require("enmap"); //this package is our Database! We will use it to save the data for ever!
const fs = require("fs"); //this package is for reading files and getting their inputs
//Creating the Discord.js Client for This Bot with some default settings ;) and with partials, so you can fetch OLD messages
const client = new Discord.Client(
fetchAllMembers: false,
restTimeOffset: 0,
shards: "auto",
restWsBridgetimeout: 100,
disableEveryone: true,
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS] // Declare the intents of your bot here.
);
require('events').EventEmitter.defaultMaxListeners = 100;
process.setMaxListeners(100);
//Loading files, with the client variable like Command Handler, Event Handler, ...
["clientvariables", "command", "events", "erelahandler", "requestreacts"].forEach(handler =>
require(`./handlers/$handler`)(client);
);
//Each Database gets a own file and folder which is pretty handy!
client.premium = new Enmap( name: "premium", dataDir: "./databases/premium" )
client.stats = new Enmap( name: "stats", dataDir: "./databases/stats" )
client.settings = new Enmap( name: "setups", dataDir: "./databases/settings" )
client.setups = new Enmap( name: "setups", dataDir: "./databases/setups" )
client.queuesaves = new Enmap( name: "queuesaves", dataDir: "./databases/queuesaves", ensureProps: false)
client.modActions = new Enmap( name: 'actions', dataDir: "./databases/warns" );
client.userProfiles = new Enmap( name: 'userProfiles', dataDir: "./databases/warns" );
//login into the bot
client.login(require("./botconfig/config.json").token);
【讨论】:
以上是关于从 github 获取此代码,尝试运行它并抛出此错误,据我所知,错误在 index.js 中,我在此处提供了 index.js 代码 [重复]的主要内容,如果未能解决你的问题,请参考以下文章
将sqlite数据库添加到jar时出现sql错误或缺少数据库
Apache Beam - 即使程序连续执行,也会捕获并抛出异常。如何停止该进程或在管道中处理