问题描述
基本上,我制作了一个简单的音乐机器人,它不播放有年龄限制的视频。
下图显示了发生的情况。我播放一个年龄限制视频,机器人加入并显示绿色圆圈,到目前为止终端没有错误。但是当我输入 ;disconnect 命令时,终端会发出一个错误,说“空结束”,这意味着机器人认为它没有播放任何歌曲,因为他们无法获取视频,因为他们必须点击一个按钮才能访问有年龄限制的视频。
有没有办法让机器人可以播放有年龄限制的视频?我已经浏览了有关此问题的问题,但找不到。提前致谢。 编辑:没什么重要的,但添加了第二张图片
const ytSearch = require('yt-search');
module.exports = {
name: 'play',aliases: [],usage: "-slowmode",description: 'Advanced music bot',run: async (client,message,args,cmd) => {
try {
const video_player = async (guild,song) => {
const song_queue = client.queue.get(guild.id);
if (!song) {
song_queue.voice_channel.leave();
client.queue.delete(guild.id);
return;
}
const stream = ytdl(song.url,{filter: 'audioonly'});
song_queue.connection.play(stream,{seek: 0,volume: 0.1})
.on('finish',() => {
song_queue.songs.shift();
video_player(guild,song_queue.songs[0]);
});
await song_queue.text_channel.send(`${song.title} is playing.`)
}
const voice_channel = message.member.voice.channel;
if(!voice_channel) return message.channel.send('You must be in a voice chat to use this command.');
const server_queue = client.queue.get(message.guild.id);
if(!args.length) return message.channel.send("Please mention a song name from YouTube or provide a link from YouTube.")
let song = {};
if (ytdl.validateURL(args[0])) {
const song_info = await ytdl.getInfo(args[0]);
song = {title: song_info.videoDetails.title,url: song_info.videoDetails.video_url}
} else {
const video_finder = async (query) =>{
const videoResult = await ytSearch(query);
return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
}
const video = await video_finder(args.join(' '));
if(video) {
song = {title: video.title,url: video.url}
} else {
message.channel.send('Cannot find the song!')
}
}
if (!server_queue){
const queue_constructor = {
voice_channel: voice_channel,text_channel: message.channel,connection: null,songs: []
}
client.queue_constructor1 = queue_constructor
client.queue.set(message.guild.id,client.queue_constructor1);
client.queue_constructor1.songs.push(song);
try {
const connection = await voice_channel.join();
client.queue_constructor1.connection = connection;
video_player(message.guild,client.queue_constructor1.songs[0]);
} catch(err) {
client.queue.delete(message.guild.id);
message.channel.send("Cannot play song for some odd reason.")
throw err;
}
} else {
server_queue.songs.push(song);
return message.channel.send(`${song.title} has been added to the queue!`)
}
}
catch(err) {
console.log(err)
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)