2017-10-17 5 views
0

私は音楽を演奏するDiscordボットを作っていますが、それは動作していますが、それは曲を再生する能力しかありません。最初の曲が終了するのを待つのではなく、最初の曲をキャンセルして2番目の曲にまっすぐに進みます。私はdiscord.jsを使用しています。私はコードをGitHubに入れました。ここに私のコードは次のとおりです。 `ディスカバリーミュージックボットに音楽用のキューがあるようにするにはどうすればよいですか?

if(command === '!music') { 
    var link = arg1 
    console.log(link) 
    const ytdl = require('ytdl-core'); 
    const streamOptions = { seek: 0, volume: 1 }; 
    const broadcast = bot.createVoiceBroadcast(); 

    if(link === undefined) { 
     bot.guilds.get(guildid).channels.get(generalchan).send("You need to put a link after !music to put a song in the queue") 
    } else { 
     if (message.member.voiceChannel) { 
      message.member.voiceChannel.join() 
       .then(connection => { // Connection is an instance of VoiceConnection 
       message.reply('SONG : ' + link); 
       const streamOptions = { seek: 0, volume: arg2/100, filter : "audioonly" }; 
       connection.playStream(ytdl(link), streamOptions); 
      }) 
     } else { 
      message.reply("You need to be in a voice channel for me to join") 
     } 
    } 
}' 

私も投票のヘルプのような人々は、現在再生している曲をスキップして、次の曲に行くために投票することができる機能をスキップします。

+0

Questionにコードを含めることはできますか? – guest271314

+0

私はちょうど、あなたが私を助けることを願って – kittrz

答えて

1

あなたの曲をキューに入れる必要があります。

このボットでは、既にこの機能を使用しているチャンネルを中断することなく、複数のサーバーで動作することを示します。ここで

あなたがキューに次の曲を再生するには、とりわけ、彼に言っている:

var servers = {}; 

function play(connection, message) { 
    var server = servers[message.guild.id]; 

    server.dispatcher = connection.playStream(YTDL(server.queue[0], { filter: 
    "audioonly" })); 

    server.dispatcher.setVolume(0.2); 

    server.queue.shift(); 

    server.dispatcher.on("end", function() { 

    if (server.queue[0]) play(connection, message); 
    else connection.disconnect(); 

}); 

} 

あなたが複数のサーバー上でこの作品を作りたい場合は、同時に必要になります.server 。

私はまた、スイッチがあります。

switch (args[0]) { 
case "play": 
     if (!args[1]) { 
      message.reply("Please provide a link") 
      return; 
     } 
     if (!message.member.voiceChannel) { 
      message.channel.send("You must be in a voice channel!") 
      return; 
     } 
     if (!servers[message.guild.id]) servers[message.guild.id] = { 
      queue: [] 
     } 
     var server = servers[message.guild.id]; 

     server.queue.push(args[1]); 

     if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function (connection) { 
       play(connection, message); 
     }); 
     break; 
case "skip": 
     var server = servers[message.guild.id]; 

     if (server.dispatcher) server.dispatcher.end(); 
     break; 

case "stop": 
     var server = servers[message.guild.id]; 

     if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect(); 
     break; 
} 

をそして、そこまで私は、メッセージの内容を尋ねます。リンクは私が歌を終了し、その次の1を開始するディスパッチャを強制する「スキップ」セクションであれば引数[1]

で与えられている場合は、私も聞いて「再生」セクションで

キューに入っています。

「停止」セクションでは、ボットはボイスチャネルを残します

関連する問題