S
S
super-boy-vasek2021-09-26 18:09:27
Node.js
super-boy-vasek, 2021-09-26 18:09:27

How to fix discord bot error?

How to fix?

Mistake:

PS C:\Users\vasek\OneDrive\Рабочий стол\Новая папка (3)> node bot.js
C:\Users\vasek\OneDrive\Рабочий стол\Новая папка (3)\node_modules\discord.js\src\client\Client.js:544
      throw new TypeError('CLIENT_MISSING_INTENTS');
      ^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
    at Client._validateOptions (C:\Users\vasek\OneDrive\Рабочий стол\Новая папка (3)\node_modules\discord.js\src\client\Client.js:544:13)
    at new Client (C:\Users\vasek\OneDrive\Рабочий стол\Новая папка (3)\node_modules\discord.js\src\client\Client.js:73:10)
    at Object.<anonymous> (C:\Users\vasek\OneDrive\Рабочий стол\Новая папка (3)\bot.js:2:15)
    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'
}

const Discord = require('discord.js'); // Подключаем библиотеку discord.js
const robot = new Discord.Client(); // Объявляем, что robot - бот
const comms = require("./comms.js"); // Подключаем файл с командами для бота
const fs = require('fs'); // Подключаем родной модуль файловой системы node.js  
let config = require('./config.json'); // Подключаем файл с параметрами и информацией
let token = config.token; // «Вытаскиваем» из него токен
let prefix = config.prefix; // «Вытаскиваем» из него префикс

robot.on("ready", function() {
  /* При успешном запуске, в консоли появится сообщение «[Имя бота] запустился!» */
  console.log(robot.user.username + " запустился!");
});


robot.on('message', (msg) => { // Реагирование на сообщения
  if (msg.author.username != robot.user.username && msg.author.discriminator != robot.user.discriminator) {
    var comm = msg.content.trim() + " ";
    var comm_name = comm.slice(0, comm.indexOf(" "));
    var messArr = comm.split(" ");
    for (comm_count in comms.comms) {
      var comm2 = prefix + comms.comms[comm_count].name;
      if (comm2 == comm_name) {
        comms.comms[comm_count].out(robot, msg, messArr);
      }
    }
  }
});


robot.login(token); // Авторизация бота

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-09-26
@super-boy-vasek

- const robot = new Discord.Client(); 
+ const robot = new Client({ intents: [Intents.FLAGS.GUILDS] });

the code is written for version 12 of discord.js.
in connection with the release of 13, there have been many changes , due to which errors may appear.

L
Loli E1ON, 2021-09-26
@E1ON

Well, apparently you need to provide intents:
https://discordjs.guide/popular-topics/intents.htm...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question