我得到类型错误代码的有效意图必须为客户端提供时,从教程编码加密机器人



这是我的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:UsersaslatOneDriveDesktopScrtBotcrypto-discord-botnode_modulesdiscord.jssrcclientClient.js:548
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:UsersaslatOneDriveDesktopScrtBotcrypto-discord-botnode_modulesdiscord.jssrcclientClient.js:548:13)
at Object.<anonymous> (C:UsersaslatOneDriveDesktopScrtBotcrypto-discord-botbot.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'
}

在你的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);

也如前所述,获得一个新的不和谐令牌,因为在这里发布它已经危及了您的机器人的安全性。

请使用当前工作目录中的结构化文件再试一次。例如:

// Importing a local module with a path relative to the `__dirname` or current
// working directory. (On Windows, this would resolve to .pathmyLocalModule.)
const myLocalModule = require('./path/myLocalModule');

相关内容

最新更新