从教程中编码加密机器人时,我收到类型错误代码,必须为客户端提供有效意图
Im getting Type error code valid intents must be provided for the Client when coding a crypto bot from a tutorial
这是我的bot.js文件
const { Client } = require('discord.js');
const dotenv = require('dotenv');
// Load environment variables
dotenv.config();
// Create a bot instance
const bot = new Client();
// Log our bot in
bot.login(process.env.DISCORD_BOT_TOKEN);
这是我的 .env 文件
DISCORD_BOT_TOKEN = my discord bot token
这是我的 .gitignore 文件
node_modules/
.env
这是错误代码
C:\Users\aslat\OneDrive\Desktop\ScrtBot\crypto-discord-bot\node_modules\discord.js\src\client\Client.js:548
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\aslat\OneDrive\Desktop\ScrtBot\crypto-discord-bot\node_modules\discord.js\src\client\Client.js:548:13)
at Object.<anonymous> (C:\Users\aslat\OneDrive\Desktop\ScrtBot\crypto-discord-bot\bot.js:9:13)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157: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:77:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
请使用当前工作目录中的结构化文件重试。例如:
// Importing a local module with a path relative to the `__dirname` or current
// working directory. (On Windows, this would resolve to .\path\myLocalModule.)
const myLocalModule = require('./path/myLocalModule');
为您的 bot.js 文件试试这个
const { Client } = require('discord.js');
const dotenv = require('dotenv');
// Load environment variables
dotenv.config();
// Create a bot instance
const bot = new Client({
// the below line is what you were missing.
intents: 32767 // you can change this if you want but that number is the code for all intents
});
// view intents here https://discord.js.org/#/docs/main/stable/class/Intents
// Log our bot in
bot.login(process.env.DISCORD_BOT_TOKEN);
同样如前所述,获取一个新的 discord 令牌,因为在此处发布它会危及您的机器人的安全。
这是我的bot.js文件
const { Client } = require('discord.js');
const dotenv = require('dotenv');
// Load environment variables
dotenv.config();
// Create a bot instance
const bot = new Client();
// Log our bot in
bot.login(process.env.DISCORD_BOT_TOKEN);
这是我的 .env 文件
DISCORD_BOT_TOKEN = my discord bot token
这是我的 .gitignore 文件
node_modules/
.env
这是错误代码
C:\Users\aslat\OneDrive\Desktop\ScrtBot\crypto-discord-bot\node_modules\discord.js\src\client\Client.js:548
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\aslat\OneDrive\Desktop\ScrtBot\crypto-discord-bot\node_modules\discord.js\src\client\Client.js:548:13)
at Object.<anonymous> (C:\Users\aslat\OneDrive\Desktop\ScrtBot\crypto-discord-bot\bot.js:9:13)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157: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:77:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
请使用当前工作目录中的结构化文件重试。例如:
// Importing a local module with a path relative to the `__dirname` or current
// working directory. (On Windows, this would resolve to .\path\myLocalModule.)
const myLocalModule = require('./path/myLocalModule');
为您的 bot.js 文件试试这个
const { Client } = require('discord.js');
const dotenv = require('dotenv');
// Load environment variables
dotenv.config();
// Create a bot instance
const bot = new Client({
// the below line is what you were missing.
intents: 32767 // you can change this if you want but that number is the code for all intents
});
// view intents here https://discord.js.org/#/docs/main/stable/class/Intents
// Log our bot in
bot.login(process.env.DISCORD_BOT_TOKEN);
同样如前所述,获取一个新的 discord 令牌,因为在此处发布它会危及您的机器人的安全。