奇妙な問題があります。このエラーはランダムに発生し、ボットが最近追加された音楽またはキューに入っている音楽を再生しようとすると発生します。その後、同じ音楽をもう一度再生しても、このエラーは発生しません。
これは私が得るエラーです:
internal/validators.js:117
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument mest be of type string. Recived undefined.
at validateString (internal/validators.js:117:11)
at Url.parse (url.js:159:3)
at Object.urlParse [as parse] (url.js.154:13)
at doDownload (/root/bot/node_modules/miniget/dist/index.js:90:28)
at processTicksAndRejections (internal/process/task_queue.js:79:11) {
code: 'ERR_INVALID_ARG_TYPE'
}
これはランダムに発生するため、これを修正する方法や原因がわかりません。私のコード:
client.on ("message", async message => {
msg = message.content.toLowerCase();
const args = message.content.split(' ');
const iskanje = args.slice(1).join(' ');
const serverQueue = queue.get(message.guild.id);
const musicplay = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Podati moraš link od glasbe oz. ime. Primer :\nplay https://www.youtube.com/watch?v=4nTTWcHD-D8\n**ali**\nplay psy daddy")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicjoin = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Moraš biti v voice kanalu, da se lahko pridružim.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicskip = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Preskočil sem glasbo.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicskipkanal = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Nisi v kanalu z botom, da bi lahko preskočil glasbo.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicneigra = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Nobena glasba se ne predvaja.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicstop = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Glasba ustavljen...")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicleave = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Zapustil sem voice kanal.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicleavekanal = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Nisi v kanalu z botom, da bi lahko uporabil to komando.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicleaveigra = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Bot ni v kanalu.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicustavil = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Ustavil sem glasbo.")
.setThumbnail("https://icons-for-free.com/iconfiles/png/512/pause+circle+outline+24px-131985190736595822.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicustavilježe = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Glasbo sem že ustavil.")
.setThumbnail("https://icons-for-free.com/iconfiles/png/512/pause+circle+outline+24px-131985190736595822.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicpredvaja = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Glasbo predvajam naprej.")
.setThumbnail("https://icons-for-free.com/iconfiles/png/512/play+icon-1320183326850327361.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicvolumeštevilka = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Prosim podaj število med 0 - 25.")
.setThumbnail("https://www.kindpng.com/picc/m/255-2559595_volume-up-font-awesome-volume-logo-no-background.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicvolumečrka = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Prosim podaj število med 0 - 25 in ne črko ipd.")
.setThumbnail("https://www.kindpng.com/picc/m/255-2559595_volume-up-font-awesome-volume-logo-no-background.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicpredvajaježe = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Glasba ni ustavljena, da bi jo lahko predvajal naprej.")
.setThumbnail("https://icons-for-free.com/iconfiles/png/512/play+icon-1320183326850327361.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicnobena = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription("Nobena glasba se ne predvaja.")
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicčakalnaigra = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Nobena glasba se ne predvaja.`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_queue_music_48px-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicloopvklop = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Vklopil sem zanko.`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/music-fill/100/Loop-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicloopizklop = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Izklopil sem zanko.`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/music-fill/100/Loop-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const playlistačakalna = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Čakalna vrsta ne bo prikazana, ker ma discord limti na 2048 črk na sporočilo + ker nočem, da bot crasha, če ma playlista preveč pesmi, ker ne more poslat sporočila.`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_queue_music_48px-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const searchnič = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Ni bilo podane številke, zato preklicujem izbiro glasbe.`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/unicons-vector-icons-pack/32/search-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const searchnull = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`
Nisi podal imena glasbe, poskusi se enkrat.
**Primer:** search my oh my`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/unicons-vector-icons-pack/32/search-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
const musicničnašel = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`
**Nič nisem našel na podlagi iskalnega niza :** ${iskanje}
Prosim poskusi še enkrat, če se ta napaka ponavlja,
kontaktiraj : Anej#0001
`)
.setThumbnail("https://cdn0.iconfinder.com/data/icons/interface-2-9/34/85-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
if(msg.startsWith(`play`)) {
message.delete();
if (!iskanje) return message.channel.send(musicplay).then(d_msg => { d_msg.delete(5000); });
const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
const voiceChannel = message.member.voiceChannel;
if (!voiceChannel) return message.channel.send(musicjoin).then(d_msg => { d_msg.delete(5000); });
if(url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for(const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await handleVideo(video2, message, voiceChannel, true);
}
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
var videos = await youtube.searchVideos(iskanje, 1);
var video = await youtube.getVideoByID(videos[0].id);
} catch (err) {
return message.channel.send(musicničnašel).then(d_msg => { d_msg.delete(5000); });
}
}
return handleVideo(video, message, voiceChannel);
}
} else if (msg.startsWith(`search`)) {
message.delete();
const voiceChannel = message.member.voiceChannel;
if (!voiceChannel) return message.channel.send(musicjoin).then(d_msg => { d_msg.delete(5000); });
if (!iskanje) return message.channel.send(searchnull).then(d_msg => { d_msg.delete(5000); });
var videos = await youtube.searchVideos(iskanje, 10);
let index = 1;
const musicsearch = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`
**Izbira glasbe:**
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
${videos.map(video2 => `**${index++} -** ${video2.title}`).join(`\n`)}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
**Podaj številko med 1-10**
`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/unicons-vector-icons-pack/32/search-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
message.channel.send(musicsearch).then(d_msg => { d_msg.delete(10000); });
try {
var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, {
maxMatches: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
return message.channel.send(searchnič).then(d_msg => { d_msg.delete(5000); });
}
const videoIndex = parseInt(response.first().content);
var video2 = await youtube.getVideoByID(videos[videoIndex - 1].id);
message.channel.bulkDelete(1);
await handleVideo(video2, message, voiceChannel);
} else if (msg.startsWith(`skip`)) {
message.delete();
if (!message.member.voiceChannel) return message.channel.send(musicskipkanal).then(d_msg => { d_msg.delete(5000); });
if (!serverQueue) return message.channel.send(musicneigra).then(d_msg => { d_msg.delete(5000); });
if (serverQueue.loop === true) {
serverQueue.loop = false;
}
serverQueue.connection.dispatcher.end();
return undefined;
} else if (msg.startsWith(`volume`)) {
message.delete();
if (!serverQueue) return message.channel.send(musicneigra).then(d_msg => { d_msg.delete(5000); });
if (!message.member.voiceChannel) return message.channel.send(musicleavekanal).then(d_msg => { d_msg.delete(5000); });
const musicvolumeglastnost = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Trenutna glastnost : ${serverQueue.volume}`)
.setThumbnail("https://www.kindpng.com/picc/m/255-2559595_volume-up-font-awesome-volume-logo-no-background.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
if (!args[1]) return message.channel.send(musicvolumeglastnost).then(d_msg => { d_msg.delete(5000); });
if (args[1] < 0 || args[1] > 25) return message.channel.send(musicvolumeštevilka).then(d_msg => { d_msg.delete(5000); });
if (isNaN(args[1])) return message.channel.send(musicvolumečrka).then(d_msg => { d_msg.delete(5000); });
serverQueue.volume = args[1];
serverQueue.connection.dispatcher.setVolume(args[1] / 5);
const musicvolumenastavil = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`Natavil sem glastnost na : ${args[1]}`)
.setThumbnail("https://www.kindpng.com/picc/m/255-2559595_volume-up-font-awesome-volume-logo-no-background.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
return message.channel.send(musicvolumenastavil).then(d_msg => { d_msg.delete(5000); });
} else if (msg.startsWith(`leave`)) {
message.delete();
let voiceChannel = message.guild.me.voiceChannel;
if (!message.member.voiceChannel) return message.channel.send(musicleavekanal).then(d_msg => { d_msg.delete(5000); });
if (serverQueue) {
serverQueue.songs = [];
serverQueue.voiceChannel.leave();
} else {
if (voiceChannel) return voiceChannel.leave();
return message.channel.send(musicleaveigra).then(d_msg => { d_msg.delete(5000); });
}
} else if (msg.startsWith(`queue`)) {
message.delete();
if (!serverQueue) return message.channel.send(musicčakalnaigra).then(d_msg => { d_msg.delete(5000); });
let čakalna = ``;
for (var i = 1; i < serverQueue.songs.length; i++) {
čakalna += `**${i}. -** [${serverQueue.songs[i].title}](https://www.youtube.com/watch?v=${serverQueue.songs[i].id})\n`;
}
const musicčakalna = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24) //${serverQueue.songs.map(song => `**${index++}. -** [${song.title}](https://www.youtube.com/watch?v=${song.id})`).join(`\n`)}
.setDescription(`
**Čakalna vrsta:**
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
${čakalna}
**Sedaj predvajam:** [${serverQueue.songs[0].title}](https://www.youtube.com/watch?v=${serverQueue.songs[0].id})
`)
.setThumbnail("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_queue_music_48px-512.png")
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
if (musicčakalna.length < 2024) return message.channel.send(musicčakalna).then(d_msg => { d_msg.delete(5000); });
return message.channel.send(playlistačakalna).then(d_msg => { d_msg.delete(10000); });
} else if (msg.startsWith(`pause`)) {
message.delete();
if (!serverQueue) return message.channel.send(musicneigra).then(d_msg => { d_msg.delete(5000); });
if (!serverQueue.playing) return message.channel.send(musicustavilježe).then(d_msg => { d_msg.delete(5000); });
if (serverQueue && serverQueue.playing) {
serverQueue.playing = false;
serverQueue.connection.dispatcher.pause();
return message.channel.send(musicustavil).then(d_msg => { d_msg.delete(5000); });
}
return message.channel.send(musicnobena).then(d_msg => { d_msg.delete(5000); });
} else if (msg.startsWith(`resume`)) {
message.delete();
if (!serverQueue) return message.channel.send(musicneigra).then(d_msg => { d_msg.delete(5000); });
if (serverQueue.playing) return message.channel.send(musicpredvajaježe).then(d_msg => { d_msg.delete(5000); });
if (serverQueue && !serverQueue.playing) {
serverQueue.playing = true;
serverQueue.connection.dispatcher.resume();
return message.channel.send(musicpredvaja).then(d_msg => { d_msg.delete(5000); });
}
return message.channel.send(musicnobena).then(d_msg => { d_msg.delete(5000); });
} else if (msg.startsWith(`loop`)) {
message.delete();
if (!serverQueue) return message.channel.send(musicneigra).then(d_msg => { d_msg.delete(5000); });
if (serverQueue.loop === false) {
serverQueue.loop = true;
return message.channel.send(musicloopvklop).then(d_msg => { d_msg.delete(5000); });
} else {
serverQueue.loop = false;
return message.channel.send(musicloopizklop).then(d_msg => { d_msg.delete(5000); });
}
}
return undefined;
});
async function handleVideo(video, message, voiceChannel, playlist = false) {
const serverQueue = queue.get(message.guild.id);
const song = {
id: video.id,
title: Util.escapeMarkdown(video.title),
url: `https://www.youtube.com/watch?v=${video.id}`
};
if (!serverQueue) {
const queueConstruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true,
loop: false
};
queue.set(message.guild.id, queueConstruct);
queueConstruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueConstruct.connection = connection;
play(message.guild, queueConstruct.songs[0]);
} catch (error) {
queue.delete(message.guild.id);
return
}
} else {
serverQueue.songs.push(song);
const musicqueue = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`GLASBA :
[${song.title}](https://www.youtube.com/watch?v=${song.id})
je bila dodana v čakalo vrsto!`)
.setImage(`https://img.youtube.com/vi/${song.id}/hqdefault.jpg`)
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
if (playlist) return undefined;
else return message.channel.send(musicqueue).then(d_msg => { d_msg.delete(5000); });
}
return undefined;
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) return queue.delete(guild.id);
const dispatcher = serverQueue.connection.playStream(ytdl(song.url), {filter: 'audioonly'})
.on('end', () => {
if (serverQueue.loop === true) serverQueue.songs.push(serverQueue.songs.shift());
else serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
});
dispatcher.setVolume(1);
const musicplay = new RichEmbed()
.setTitle(" Glasba ")
.setColor(0xFF1E24)
.setDescription(`PREDVAJAM GLASBO :
[${song.title}](https://www.youtube.com/watch?v=${song.id})`)
.setImage(`https://img.youtube.com/vi/${song.id}/hqdefault.jpg`)
.setFooter('Za izboljšavo pišite predloge na: Anej#0001');
serverQueue.textChannel.send(musicplay).then(d_msg => { d_msg.delete(5000); });
}
client.login (token);