Problème débogage pour Bot Discord

Par Dreyko, il y a 3 ans


Bonjour, j'ai une erreur lorsque j'essaye de faire un débogage, c'est celle-ci:

Uncaught TypeError TypeError: Intents is not a constructor
at <anonymous> (c:\Users\moi\Desktop\NOM_DE_MON_DOSSIER\index.js:7:17)
at Module._compile (internal/modules/cjs/loader:1159:14)
at Module._extensions..js (internal/modules/cjs/loader:1213:10)
at Module.load (internal/modules/cjs/loader:1037:32)
at Module._load (internal/modules/cjs/loader:878:12)
at executeUserEntryPoint (internal/modules/run_main:81:12)
at <anonymous> (internal/main/run_main_module:23:47)

const Discord = require('discord.js'); const { Intents } = Discord; const ytdl = require('ytdl-core'); const TOKEN = 'mon token'; const intents = new Intents(); // Créez une instance de l'objet Intents intents.add(Intents.GUILDS_MESSAGES); intents.add(Intents.GUILD_MEMBERS); intents.add(Intents.GUILD_VOICE_STATES); const client = new Discord.Client({ intents: intents }); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('message', message => { if (message.content.startsWith('!play')) { const searchString = message.content.split(' ').slice(1).join(' '); const url = `https://www.youtube.com/results?search_query=${encodeURIComponent(searchString)}`; ytdl.getInfo(url, (err, info) => { if (err) return console.error(err); const video = info.videos[0]; const videoURL = `https://www.youtube.com/watch?v=${video.video_id}`; message.channel.send(`Playing: ${video.title}`); message.member.voice.channel.join().then(connection => { connection.play(ytdl(videoURL, { filter: 'audioonly' })); }); }); } }); client.login("mon token");

Ce que j'ai essayer de faire pour régler l'erreur:

Quelqu'un à une idée s'il vous plait ? :(

1 réponse

Orivoir21, il y a 3 ans

Bonjour, le message d'erreur est assez explicite:

Intents is not a constructor

tu peux faire un log de Intents pour observer sa valeur mais à priori tu peux pas l'intancier.
Du coups ces cette ligne qui plante:

const intents = new Intents();

De mon côté pour la version 14.7.1 de discord.js Discord.Intents est undefined

Tu peux faire un:

console.log(Intents);

Pour voir ce qu'il contient.

A noter que le guide de discord.js à l'air de montrer une façon de paramètrer les intents en utilisant une classe GatewayIntentBits
de cette maniére la:

const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers, ], });

Voir Discord.js guide intents