Хотел сделать бота для воспроизведения музыки из ролика YouTube на discord.js + discordjs/voice. Бот работает, но после 30-60 секунд плеер уходит в автопаузу.
Как это отключить ?
Версии Discord.js v 14, discordjs/voice v 9.6.1
Вот исходный код:
const ytdl = require('ytdl-core');
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType } = require('@discordjs/voice');
const config = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] });
const prefix = 'F.';
client.once(Events.ClientReady, c => {
console.log(`Бот ${c.user.tag} залогинился`);
});
client.on('messageCreate', async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
async function play() {
const connect = joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.member.guild.id,
adapterCreator: message.member.guild.voiceAdapterCreator,
});
const player = createAudioPlayer();
const stream = ytdl(args.join(' '), { filter: 'audioonly' });
const resource = createAudioResource(stream, { inputType: StreamType.Arbitrary });
connect.subscribe(player);
player.play(resource);
}
switch (command) {
case 'play':play(); break;
default: message.react('❌');
}
});
client.login(config.token2);