我为粉丝服务器制作了一个自定义的 Discord 机器人,该服务器由 Heroku 托管,因此当我不在时它可以保持在线状态。我想做的是,当有人为其发出特定命令时,让机器人播放其文件夹中的 mp3 文件,但我希望音乐在特定语音通道中播放。
首先,我尝试将其视为图像文件。例如:
if (message.content == "Play the Funky Tune.")
{
message.reply("Of course, I hope you enjoy!", { files: ["./Music/FunkyTune.mp3"] });
}
然而,这会导致机器人将音乐文件放在那里,虽然您可以单击它并播放它,但当您单击另一个频道时,音乐就会暂停。我希望它在特定的语音通道中播放歌曲,以便当用户单击另一个通道时它会继续播放。
在为此进行研究时,每个主题总是要求提供 YouTube 视频链接,将其转换为音频,但这不是我想要的,因为 YouTube 视频可能会发生任何事情。
P.S. 我对使用已经制作的机器人不感兴趣,我想将这个音乐功能集成到我自己的机器人中。
if (message.content == "Play the Funky Tune.") {
// Checking if the message author is in a voice channel.
if (!message.member.voice.channel) return message.reply("You must be in a voice channel.");
// Checking if the bot is in a voice channel.
if (message.guild.me.voice.channel) return message.reply("I'm already playing.");
// Joining the channel and creating a VoiceConnection.
message.member.voice.channel.join().then(VoiceConnection => {
// Playing the music, and, on finish, disconnecting the bot.
VoiceConnection.play("./Music/FunkyTune.mp3").on("finish", () => VoiceConnection.disconnect());
message.reply("Playing...");
}).catch(e => console.log(e))
};
请注意,您必须运行以下命令才能使其正常工作:
npm install ffmpeg-static
npm install @discordjs/opus
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)