Вот код, снизу ошибка, бот не работает, знаю что была изменена работа с интентами, но что делать и как исправить не знаю.
const { Client, Intents } = require('discord.js');
const ytdl = require('ytdl-core');
const ytSearch = require('youtube-search');
const token = 'token'; //ds token
const client = new Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
] });
const opts = {
maxResults: 5,
key: 'token', // youtube api
type: 'video',
};
let dispatcher = null;
let repeat = false;
client.once('ready', () => {
console.log('Bot is online!');
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
const voiceChannel = message.member.voice.channel;
if (message.content.startsWith('!play')) {
if (!voiceChannel) {
return message.channel.send(
'Вы должны находиться в голосовом каналe, чтобы проиграть музыку!'
);
}
const searchQuery = message.content.replace('!play', '').trim();
try {
const results = await ytSearch(searchQuery, opts);
const videoURL = results[0].link;
const connection = await voiceChannel.join();
const stream = ytdl(videoURL, { filter: 'audioonly' });
dispatcher = connection.play(stream, { seek: 0, volume: 1 });
dispatcher.on('finish', () => {
if (repeat) {
dispatcher = connection.play(stream, { seek: 0, volume: 1 });
} else {
voiceChannel.leave();
dispatcher = null;
}
});
} catch (error) {
console.error(error);
message.channel.send('Произошла ошибка при воспроизведении музыки!');
}
}
if (message.content === '!stop') {
if (dispatcher) {
dispatcher.end();
dispatcher = null;
voiceChannel.leave();
}
}
if (message.content === '!skip') {
dispatcher.end();
dispatcher = null;
}
if (message.content === '!repeat') {
repeat = !repeat;
message.channel.send(`Режим повтора воспроизведения: ${repeat ? 'Включен' : 'Выключен'}`);
}
});
client.login(token);
ОШИБКА: Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'FLAGS'
at <anonymous> (g:\All_Code\marry_web\bot_discord_music.js:8:9)
at Module._compile (internal/modules/cjs/loader:1254:14)
at Module._extensions..js (internal/modules/cjs/loader:1308:10)
at Module.load (internal/modules/cjs/loader:1117:32)
at Module._load (internal/modules/cjs/loader:958:12)
at executeUserEntryPoint (internal/modules/run_main:81:12)
at <anonymous> (internal/main/run_main_module:23:47)
const { Client, Intents } = require('discord.js');
const ytdl = require('ytdl-core');
const ytSearch = require('youtube-search');
const token = 'token'; //ds token
const client = new Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
] });
const opts = {
maxResults: 5,
key: 'token', // youtube api
type: 'video',
};
let dispatcher = null;
let repeat = false;
client.once('ready', () => {
console.log('Bot is online!');
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
const voiceChannel = message.member.voice.channel;
if (message.content.startsWith('!play')) {
if (!voiceChannel) {
return message.channel.send(
'Вы должны находиться в голосовом каналe, чтобы проиграть музыку!'
);
}
const searchQuery = message.content.replace('!play', '').trim();
try {
const results = await ytSearch(searchQuery, opts);
const videoURL = results[0].link;
const connection = await voiceChannel.join();
const stream = ytdl(videoURL, { filter: 'audioonly' });
dispatcher = connection.play(stream, { seek: 0, volume: 1 });
dispatcher.on('finish', () => {
if (repeat) {
dispatcher = connection.play(stream, { seek: 0, volume: 1 });
} else {
voiceChannel.leave();
dispatcher = null;
}
});
} catch (error) {
console.error(error);
message.channel.send('Произошла ошибка при воспроизведении музыки!');
}
}
if (message.content === '!stop') {
if (dispatcher) {
dispatcher.end();
dispatcher = null;
voiceChannel.leave();
}
}
if (message.content === '!skip') {
dispatcher.end();
dispatcher = null;
}
if (message.content === '!repeat') {
repeat = !repeat;
message.channel.send(`Режим повтора воспроизведения: ${repeat ? 'Включен' : 'Выключен'}`);
}
});
client.login(token);
ОШИБКА: Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'FLAGS'
at <anonymous> (g:\All_Code\marry_web\bot_discord_music.js:8:9)
at Module._compile (internal/modules/cjs/loader:1254:14)
at Module._extensions..js (internal/modules/cjs/loader:1308:10)
at Module.load (internal/modules/cjs/loader:1117:32)
at Module._load (internal/modules/cjs/loader:958:12)
at executeUserEntryPoint (internal/modules/run_main:81:12)
at <anonymous> (internal/main/run_main_module:23:47)