前提
Discord.js(v14)でBotを作っています。
最初に
javascript
1const { GatewayIntentBits } = require("discord.js")
と書く際に、なぜGatewayIntentBitsを{}で囲わなければいけないのかが調べてもよくわかりませんでした。
{}で囲わずに実行したときに出たエラーメッセージ
javascript
1C:\DiscordBotProject\node_modules\discord.js\src\util\BitField.js:168 2 throw new DiscordjsRangeError(ErrorCodes.BitFieldInvalid, bit); 3 ^ 4 5RangeError [BitFieldInvalid]: Invalid bitfield flag or number: class BaseClient extends EventEmitter { 6 constructor(options = {}) { 7 super({ captureRejections: true }); 8 9 if (typeof options !== 'object' || options === null) { 10 throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true); 11 } 12 13 /** 14 * The options the client was instantiated with 15 * @type {ClientOptions} 16 */ 17 this.options = mergeDefault(Options.createDefault(), options); 18 19 /** 20 * The REST manager of the client 21 * @type {REST} 22 */ 23 this.rest = new REST(this.options.rest); 24 } 25 26 /** 27 * Destroys all assets used by the base client. 28 * @returns {void} 29 */ 30 destroy() { 31 this.rest.requestManager.clearHashSweeper(); 32 this.rest.requestManager.clearHandlerSweeper(); 33 } 34 35 /** 36 * Increments max listeners by one, if they are not zero. 37 * @private 38 */ 39 incrementMaxListeners() { 40 const maxListeners = this.getMaxListeners(); 41 if (maxListeners !== 0) { 42 this.setMaxListeners(maxListeners + 1); 43 } 44 } 45 46 /** 47 * Decrements max listeners by one, if they are not zero. 48 * @private 49 */ 50 decrementMaxListeners() { 51 const maxListeners = this.getMaxListeners(); 52 if (maxListeners !== 0) { 53 this.setMaxListeners(maxListeners - 1); 54 } 55 } 56 57 toJSON(...props) { 58 return flatten(this, ...props); 59 } 60}. 61 at IntentsBitField.resolve (C:\DiscordBotProject\node_modules\discord.js\src\util\BitField.js:168:11) 62 at C:\DiscordBotProject\node_modules\discord.js\src\util\BitField.js:163:54 63 at Array.map (<anonymous>) 64 at new BitField (C:\DiscordBotProject\node_modules\discord.js\src\util\BitField.js:33:38) 65 at new IntentsBitField (C:\DiscordBotProject\node_modules\discord.js\src\util\IntentsBitField.js:9:1) 66 at Client._validateOptions (C:\DiscordBotProject\node_modules\discord.js\src\client\Client.js:491:25) 67 at new Client (C:\DiscordBotProject\node_modules\discord.js\src\client\Client.js:78:10) 68 at Object.<anonymous> (C:\DiscordBotProject\index.js:13:16) 69 at Module._compile (node:internal/modules/cjs/loader:1218:14) { 70 code: 'BitFieldInvalid' 71} 72 73Node.js v18.13.0
該当のソースコード
javascript
1const GatewayIntentBits = require("discord.js");
試したこと
検索
補足情報(FW/ツールのバージョンなど)
Node.js v18.13.0.
Discord.js v14.7.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。