Discord 音乐机器人随机切断音乐

时间:2021-08-01 12:15:13

标签: javascript node.js discord discord.js ytdl

我正在尝试制作一个音乐机器人,我昨天才开始(使用 discord.js 的语音方面,但我编写普通机器人的时间已经更长了)所以我对语音真的很陌生,我不知道我是否遗漏了一些简单的东西,但无论如何我做了这个代码:

spec:
  containers:
    - args: []
      command: []
      env:
        - name: AIRFLOW__KUBERNETES__RUN_AS_USER
          value: 10000 # Or your user ID.

它只是在 youtube 上搜索视频(使用 ytdl-core 和 ytdl-search),但音频会随机中断,这是它给出的错误: enter image description here

我认为错误的部分可能是 var voiceChannel = message.member.voice.channel; if (!voiceChannel) return message.channel.send("You have to join a voice channel!") voiceChannel.join() console.log(`joined channel: ${message.channel.name}`); const videoFinder = async (query) => { const videoResult = await ytSearch(query); return (videoResult.videos.length > 1) ? videoResult.videos[0] : null; } const streamOptions = { seek: 0, volume: 1 }; const video = await videoFinder(args.join(' ')); if (!video) return message.channel.send("The video you searched wasn't found!") voiceChannel.join().then(async connection => { const stream = ytdl(video.url, { filter: 'audioonly' }); const dispatcher = await connection.play(stream, streamOptions) dispatcher.on('start', () => { console.log('audio is now playing!'); }); dispatcher.on('finish', () => { console.log('audio has finished playing!'); }); dispatcher.on('error', console.error); const videoEmbed = new Discord.MessageEmbed() .setColor("RANDOM") .setDescription(`Now playing: [${video.title}](${video.url})`) .addFields( { name: 'Author:', value: `${video.author.name}`, inline: true }, { name: 'Duration:', value: `${video.timestamp}`, inline: true }, { name: 'Released:', value: `${video.ago}`, inline: true }, ) .setImage(video.image) .setFooter(`Total views: ${video.views}`) .setTimestamp() message.channel.send(videoEmbed) ,但我不确定。

0 个答案:

没有答案