@tresosh

Как исправить «TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.»?

Код:

const Discord = require('discord.js'); 
const bot = new Discord.Client();
let config = require('./botconfig.json'); 
let token = config.token; 
let prefix = config.prefix;
bot.on('ready', () => { 
  console.log(`Запустился бот ${bot.user.username}`);
});
bot.on('message', message => {
  if (message.content === prefix + 'pong') {
    message.reply('Ping!');
  }
});
bot.login(token);

Что выдает вместо запуска бота:

PS D:\рабочий стол\MyBot> node bot.js
D:\рабочий стол\MyBot\node_modules\discord.js\src\client\Client.js:512
      throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
      ^

TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
    at Client._validateOptions (D:\рабочий стол\MyBot\node_modules\discord.js\src\client\Client.js:512:13)
    at new Client (D:\рабочий стол\MyBot\node_modules\discord.js\src\client\Client.js:80:10)
    at Object.<anonymous> (D:\рабочий стол\MyBot\bot.js:2:13)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'ClientMissingIntents'
}

Версия Node.js: v20.9.0
  • Вопрос задан
  • 135 просмотров
Решения вопроса 1
Alexandre888
@Alexandre888 Куратор тега discord.js
Javascript-разработчик
const { Client, GatewayIntentBits } = require("discord.js");
const bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const { token, prefix } = require('./botconfig.json');

bot.on("ready", () => {
  // ... //
});

bot.on("messageCreate", message => {
  // ... //
});

bot.login(token);
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы