我是新手,我想知道是否有办法让我的机器人播放特定的 YouTube URL
所以当我输入 s1 时,机器人会加入房间并播放该 URL
if (message.content == "s1") {
if (!message.member.voice.channel) return message.reply("You have to be in a VoiceChannel");
message.member.voice.channel.join().then(VoiceConnection => {
VoiceConnection.play("https://youtu.be/~~~~").on("finish", () =>
VoiceConnection.disconnect());
message.reply("done");
}).catch(e => console.log(e))
};
最佳答案
您需要使用一个名为 ytdl 的包来执行此操作:https://www.npmjs.com/package/ytdl-core
在终端你做npm install ytdl-core@latest
然后添加 const ytdl = require('ytdl-core');
到您的 js 文件的顶部。
那么你需要改变
VoiceConnection.play("https://youtu.be/~~~~").on("finish", () =>
至VoiceConnection.play(ytdl("https://youtu.be/~~~~")).on("finish", () =>
关于node.js - 如何让 Discord Bot 播放 YouTube URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66507956/