UnhandledPromiseRejectionWarning: ReferenceError: voice is not defined - javascript

I realize that posts about this kind of topic exists, but I'm really new to JS and wouldn't really be able to understand if it's not about what I'm doing specifically. I'm trying to make a music bot for discord following along and trying to learn from a tutorial, and it didn't recognize that I was in a voice channel, so it wouldn't play anything. Then this error started showing up after a little looking around to see what I did wrong. It also gives me this error message: UnhandledPromiseRejectionWarning: Unhandled promise rejection. Which I'm not really sure how to fix. It says "This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()." But again, as I'm new to this I really don't understand what that means.
Ignore the ill-mannered Swedish by the way, but here is the entire thing:
const Discord = require('discord.js');
const {
prefix,
token,
} = require('./config.json');
const ytdl = require('ytdl-core');
const client = new Discord.Client();
const queue = new Map();
client.once('ready', () => {
console.log('Ready!');
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('¨Disconnect!');
});
client.on('message', async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const serverQueue = queue.get(message.guild.id);
if (message.content.startsWith(`${prefix}play`)) {
execute(message, serverQueue);
return;
} else if (message.content.startsWith(`${prefix}play`)) {
skip(message, serverQueue);
} else if (message.content.startsWith(`${prefix}stop`)) {
stop(message, serverQueue);
return;
}
});
async function execute(message, serverQueue) {
const args = message.content.split(" ");
const voiceChannel = message.member.voice.Channel;
if (!voice.channel)
return message.channel.send(
"Hur fan ska jag kunna spela musik om du inte är i en kanal? Jävla mongo."
);
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"Ok, så du vill att jag spelar upp musik, men ger mig inte tillåtelse att spela upp musik? Fixa dina perms dumfan."
);
}
let song;
if (ytdl.validateURL(args[1])) {
const songInfo = await ytdl.getInfo(args[1]);
song = {
title: songInfo.title,
url: songInfo.video_url
};
} else {
const {videos} = await yts(args.slice(1).join(" "));
if (!videos.length) return message.channel.send("No songs were found!");
song = {
title: videos[0].title,
url: videos[0].url
};
}
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true,
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
}else {
serverQueue.songs.push(song);
return message.channel.send(`${song.title}? Ok, lägger till den i kön.`);
}
}
function skip(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"Du måste var i en röstkanal för att stoppa musik din dumma jävel."
);
if (!serverQueue)
return message.channel.send("Det finns ingen låt att skippa dtt sär.");
serverQueue.connection.dispatcher.end();
}
function stop(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"Du måste var i en röstkanal för att stoppa musik din dumma jävel."
);
if (!serverQueue)
return message.channel.send("Det finns ingen låt att stoppa dtt sär.");
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on("finish", () => {
serverQueue.songs-shift();
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolume.Logarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`Nu spelar jag: **${song.title}** din hora`);
}
client.login(token);
Don't know if I did this post right...
And sorry about the formatting.
Thanks in advance though!

Related

Discordjs add space between prefix and command

I created a music bot that streams music when someone taps !play in-text channel
Now I want to switch !play with please play but it response only with pleaseplay with no space between them and when I tried to change the code:
const prefix = 'please'; //before
const prefix = 'please '; //after
but it doesn't work at all with an error
log (node:5296) UnhandledPromiseRejectionWarning: Error: No video id found:
const {Client, Attachment, Message} = require('discord.js');
const {token} = require("./config.json");
const bot = new Client();
const prefix = 'please ';
const ytdl = require("ytdl-core");
const request = require('request');
const cheerio = require('cheerio');
const queue = new Map();
bot.on('ready', () => {
console.log('Client is online!');
bot.on("message", async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const serverQueue = queue.get(message.guild.id);
if (message.content.startsWith(`${prefix}play`)) {
execute(message, serverQueue);
return;
} else if (message.content.startsWith(`${prefix}skip`)) {
skip(message, serverQueue);
return;
} else if (message.content.startsWith(`${prefix}stop`)) {
stop(message, serverQueue);
return;
} else {
message.channel.send("You need to enter a valid command!");
}
});
async function execute(message, serverQueue) {
const args = message.content.split(" ");
const voiceChannel = message.member.voice.channel;
if (!voiceChannel)
return message.channel.send(
"You need to be in a voice channel to play music!"
);
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"I need the permissions to join and speak in your voice channel!"
);
}
const songInfo = await ytdl.getInfo(args[1]);
const song = {
title: songInfo.title,
url: songInfo.video_url
};
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
} else {
serverQueue.songs.push(song);
return message.channel.send(`${song.title} has been added to the queue!`);
}
}
function skip(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in a voice channel to stop the music!"
);
if (!serverQueue)
return message.channel.send("There is no song that I could skip!");
serverQueue.connection.dispatcher.end();
}
function stop(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in a voice channel to stop the music!"
);
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on("finish", () => {
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`streaming: **${song.title}**`);
}
bot.login(token);
The problem is that your arguments are split based on the space character.
const args = message.content.split(" ");
args[1] is being referenced to get the text after the command name, but with the space in the command, args[1] will always be "play" (or whichever command they are using)
A quick fix would be to change args[1] to args[2]
const songInfo = await ytdl.getInfo(args[2]);
Edit: Full upgraded code... also clear like a crystal.
const {Client, Attachment, Message} = require('discord.js');
const {token} = require("./config.json");
const bot = new Client();
const prefix = 'please';
const ytdl = require("ytdl-core");
const request = require('request');
const cheerio = require('cheerio');
const queue = new Map();
bot.on('ready', () => {
console.log('Client is online!');
}
bot.on("message", async message => {
let content = message.content.split(' ');
if (message.author.bot) return;
if (content.shift() !== prefix) return;
const serverQueue = queue.get(message.guild.id);
switch (content.shift()) {
case 'play': exec(content, message, serverQueue); break;
case 'skip': skip(content, message, serverQueue); break;
case 'stop': stop(content, message, serverQueue); break;
default: message.channel.send("You need to enter a valid command!");
}
});
async function exec (ctx, msg, que) {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel)
return msg.channel.send(
"You need to be in a voice channel to play music!"
);
const permissions = voiceChannel.permissionsFor(msg.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK"))
return msg.channel.send(
"I need the permissions to join and speak in your voice channel!"
);
const songInfo = await ytdl.getInfo(ctx.join(' '));
const song = {
title: songInfo.title,
url: songInfo.video_url
};
if (!que) {
const queueContruct = {
textChannel: msg.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
queue.set(msg.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(msg.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(msg.guild.id);
return msg.channel.send(err);
}
} else {
que.songs.push(song);
return msg.channel.send(`${song.title} has been added to the queue!`);
}
}
await function play(gui, sng) {
const serverQueue = queue.get(gui.id);
if (!sng) {
serverQueue.voiceChannel.leave();
queue.delete(gui.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(sng.url))
.on("finish", () => {
serverQueue.songs.shift();
play(gui, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`streaming: **${sng.title}**`);
}
async function stop(ctx, msg, que) {
if (!msg.member.voice.channel)
return msg.channel.send(
"You have to be in a voice channel to stop the music!"
);
que.songs = [];
que.connection.dispatcher.end();
}
async function skip(ctx, msg, que) {
if (!msg.member.voice.channel)
return msg.channel.send(
"You have to be in a voice channel to stop the music!"
);
if (!que)
return msg.channel.send("There is no song that I could skip!");
que.connection.dispatcher.end();
}
bot.login(token);

Erro:SyntaxError: Unexpected token ':' in MUSIC BOT

I am creating a music bot, and one command of he is prefix + "play", and in the chat I put "!play + [a youtube link]", but this error appeared on the console. The code of "play" is:
===================================================================
const Discord = require('discord.js');
const ytdl = require("ytdl-core");
module.exports.run = async (bot, message, args) => {
name: "play",
description: "Play a song in your channel!",
async execute(message) {
try {
const args = message.content.split(" ");
const queue = message.client.queue;
const serverQueue = message.client.queue.get(message.guild.id);
const voiceChannel = message.member.voice.channel;
if (!voiceChannel)
return message.channel.send(
"You need to be in a voice channel to play music!"
);
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"I need the permissions to join and speak in your voice channel!"
);
}
const songInfo = await ytdl.getInfo(args[1]);
const song = {
title: songInfo.videoDetails.title,
url: songInfo.videoDetails.video_url
};
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
this.play(message, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
} else {
serverQueue.songs.push(song);
return message.channel.send(
`${song.title} has been added to the queue!`
);
}
} catch (error) {
console.log(error);
message.channel.send(error.message);
}
},
play(message, song) {
const queue = message.client.queue;
const guild = message.guild;
const serverQueue = queue.get(message.guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on("finish", () => {
serverQueue.songs.shift();
this.play(message, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`Starting play: **${song.title}**`);
}
};
===================================================================
The error is: "Erro:SyntaxError: Unexpected token ':'".
Someone can help me plese?
If its supposed to return an object, put parentheses around it, like this:
// From
module.exports.run = async (bot, message, args) => {
...
};
// To
module.exports.run = async (bot, message, args) => ({
...
});
``

Discord.js music bot with queue doesn't work

I am trying to make a music Discord Bot with a queue. Currently, the play command work and I can add music to the queue (displayed with my playlist command). The problem is when the first music ends, the bot completly stops and do not play the next song (it do not disconnect and looks like it's playing something).
I use Discord.js v12, ffmpeg-static and the Youtube API.
if (command === "play" || command === "p") {
const args = message.content.split(" ");
const searchString = args.slice(1).join(" ");
if (!args[1]) {
return message.channel.send('Il faut spécifier une URL !')
.catch(console.error);
}
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const serverQueue = queue.get(message.guild.id);
var voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send("Tu dois être dans un salon vocal pour utiliser cette commande !");
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT")) {
return message.channel.send("J'ai besoin de la permission **`CONNECT`** pour cette commande");
}
if (!permissions.has("SPEAK")) {
return message.channel.send("J'ai besoin de la permission **`SPEAK`** pour parler");
}
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); // eslint-disable-line no-await-in-loop
await handleVideo(video2, message, voiceChannel, true); // eslint-disable-line no-await-in-loop
}
return message.channel.send(`:white_check_mark: **|** Playlist: **\`${playlist.title}\`** a été ajouté à la playlist !`);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
// eslint-disable-next-line max-depth
try {
} catch (err) {
console.error(err);
return message.channel.send("Annulation de la commande...");
}
const videoIndex = parseInt(1);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) {
console.error(err);
return message.channel.send("🆘 **|** Je n'obtiens aucun résultat :pensive:");
}
}
return handleVideo(video, message, voiceChannel);
}
}
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}`
};
console.log(song.url)
if (!serverQueue) {
const queueConstruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
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) {
console.error(`Je ne peux pas rejoindre le salon vocal : ${error}`);
queue.delete(message.guild.id);
return message.channel.send(`Je ne peux pas rejoindre le salon vocal : **\`${error}\`**`);
}
} else {
serverQueue.songs.push(song);
if (playlist) return undefined;
else return message.channel.send(`:white_check_mark: **|** **\`${song.title}\`** a été ajouté à la playlist !`);
}
return undefined;
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection.play(ytdl(song.url))
.on("end", reason => {
if (reason === "Stream is not generating quickly enough.") console.log("Musique terminée.");
else console.log(reason);
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`🎶 **|** En cours de lecture : **\`${song.title}\`**`);
};
Try replacing "end" with "finish":
const dispatcher = serverQueue.connection.play(ytdl(song.url)).on("end", reason => {
to
const dispatcher = serverQueue.connection.play(ytdl(song.url)).on("finish", reason => {

(node:656) UnhandledPromiseRejectionWarning: ReferenceError: prefix is not defined error

I'm currently trying to get my Discord bot to play music in the Discord, I have all this code typed up and it's coming up with this error:
(node:656) UnhandledPromiseRejectionWarning: ReferenceError: prefix is not defined
I've tried fixing it but can't. I'm using JavaScript and the program I'm using is Visual Studio Code.
Here's the code:
const {Client, MessageEmbed} = require('discord.js');
const bot = new Client();
const queue = new Map();
const ytdl = require("ytdl-core");
const token = 'HIDDEN FOR PRIVACY';
const PREFIX = '!';
var version = "1.0.0"
bot.on('ready', () =>{
console.log('Krum has started');
bot.user.setActivity(`!help | Krums Bot`);
})
//ATTEMPT AT PLAYING MUSIC--LOOKING FOR FIX--NOT WORKING CURRENTLY
bot.on("message", async message => {
if (message.author.bot) return;
if (!message.content.startsWith(PREFIX)) return;
const serverQueue = queue.get(message.guild.id);
if (message.content.startsWith(`${PREFIX}play`)) {
execute(message, serverQueue);
return;
} else if (message.content.startsWith(`${PREFIX}skip`)) {
skip(message, serverQueue);
return;
} else if (message.content.startsWith(`${PREFIX}stop`)) {
stop(message, serverQueue);
return;
} else {
message.channel.send("You need to enter a valid command!");
}
});
async function execute(message, serverQueue) {
const args = message.content.split(" ");
const voiceChannel = message.member.voice.channel;
if (!voiceChannel)
return message.channel.send(
"You need to be in a voice channel to play music!"
);
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"I need the permissions to join and speak in your voice channel!"
);
}
const songInfo = await ytdl.getInfo(args[1]);
const song = {
title: songInfo.title,
url: songInfo.video_url
};
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
} else {
serverQueue.songs.push(song);
return message.channel.send(`${song.title} has been added to the queue!`);
}
}
function skip(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in a voice channel to stop the music!"
);
if (!serverQueue)
return message.channel.send("There is no song that I could skip!");
serverQueue.connection.dispatcher.end();
}
function stop(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in a voice channel to stop the music!"
);
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on("finish", () => {
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`Start playing: **${song.title}**`);
}

My Discord Music bot executes an object instead of text

I tried to make a music bot, but it wont execute the song. Below is the code for the section which should gather the information and execute the song.
Can someone help me get this right? I'm not sure how to fix this issue as I don't know where the error starts.
I pasted also the handleVideo and the play class in the end so you know what happens there.
if (command === 'play') {
const voiceChannel = message.member.voiceChannel;
if (!voiceChannel) return message.channel.send('I\'m sorry but you need to be in a voice channel to play music!');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) {
return message.channel.send('I cannot connect to your voice channel, make sure I have the proper permissions!');
}
if (!permissions.has('SPEAK')) {
return message.channel.send('I cannot speak in this voice channel, make sure I have the proper permissions!');
}
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); // eslint-disable-line no-await-in-loop
await handleVideo(video2, message, voiceChannel, true); // eslint-disable-line no-await-in-loop
}
return message.channel.send(`✅ Playlist: **${playlist.title}** has been added to the queue!`);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
message.channel.send(`
__**Song selection:**__
${videos.map(video2 => `**${++index} -** ${video2.title}`).join('\n')}
Please provide a value to select one of the search results ranging from 1-10.
`);
// eslint-disable-next-line max-depth
try {
var response = await message.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
maxMatches: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
console.error(err);
return message.channel.send('No or invalid value entered, cancelling video selection.');
}
const videoIndex = parseInt(response.first().content);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) {
console.error(err);
return message.channel.send('🆘 I could not obtain any search results.');
}
}
return handleVideo(video, message, voiceChannel);
}
}
async function handleVideo(video, message, voiceChannel, playlist = false) {
const serverQueue = queue.get(message.guild.id);
console.log(video);
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
};
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) {
console.error(`I could not join the voice channel: ${error}`);
queue.delete(message.guild.id);
return message.channel.send(`I could not join the voice channel: ${error}`);
}
} else {
serverQueue.songs.push(song);
console.log(serverQueue.songs);
if (playlist) return undefined;
else return message.channel.send(`✅ **${song.title}** has been added to the queue!`);
}
return undefined;
});
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
console.log(serverQueue.songs);
const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
.on('end', reason => {
if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
else console.log(reason);
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on('error', error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(`🎶 Start playing: **${song.title}**`);
}
The error message:
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
at validateString (internal/validators.js:125:11)
at normalizeSpawnArguments (child_process.js:411:3)
at Object.spawn (child_process.js:545:16)
at new FfmpegProcess (C:\Users\user\Desktop\ExoBot-master\node_modules\prism-media\src\transcoders\ffmpeg\FfmpegProcess.js:14:33)
at FfmpegTranscoder.transcode (C:\Users\user\Desktop\ExoBot-master\node_modules\prism-media\src\transcoders\ffmpeg\Ffmpeg.js:34:18)
at MediaTranscoder.transcode (C:\Users\user\Desktop\ExoBot-master\node_modules\prism-media\src\transcoders\MediaTranscoder.js:27:31)
at Prism.transcode (C:\Users\user\Desktop\ExoBot-master\node_modules\prism-media\src\Prism.js:13:28)
at AudioPlayer.playUnknownStream (C:\Users\user\Desktop\ExoBot-master\node_modules\discord.js\src\client\voice\player\AudioPlayer.js:97:35)
at VoiceConnection.playStream (C:\Users\user\Desktop\ExoBot-master\node_modules\discord.js\src\client\voice\VoiceConnection.js:478:24)
at play (C:\Users\user\Desktop\ExoBot-master\bot.js:322:44)

Categories

Resources