I'm doing a 'Now Playing' command using distube.js, but when I try to pull the information from which channel published the song it comes out as 'undefined' nowplaying embed image
These are the track informations.
Does anyone have any tips to help me?
The code I have so far
const { MessageEmbed } = require("discord.js");
const { errorbuilder } = require("../../handlers/functions");
const ee = require("../../botconfig/embed.json");
const bar = require(`stylish-text`)
module.exports = {
name: "nowplaying",
description: "Mostra os detalhes da música que está tocando",
permissions: ['SEND_MESSAGES'],
usage: "",
aliases: ["np", "nowplay"],
execute: async (client, message, args, Discord, cmd) => {
try {
const { channel } = message.member.voice;
if (!channel)
return message.channel.send(new MessageEmbed()
.setColor(ee.wrongcolor)
.setFooter(ee.footertext)
.setTitle(`❌ ERROR | Por favor entre em um canal primeiro`)
);
if (!client.distube.getQueue(message))
return message.channel.send(new MessageEmbed()
.setColor(ee.wrongcolor)
.setFooter(ee.footertext)
.setTitle(`❌ ERROR | Eu não estou tocando nada`)
.setDescription(`Fila vazia`)
);
if (client.distube.getQueue(message) && channel.id !== message.guild.me.voice.channel.id)
return message.channel.send(new MessageEmbed()
.setColor(ee.wrongcolor)
.setFooter(ee.footertext)
.setTitle(`❌ ERROR | Por favor entre no **meu** canal`)
.setDescription(`Canal: <#${message.guild.me.voice.channel.id}>`)
);
let queue = client.distube.getQueue(message);
let track = queue.songs[0];
console.log(track)
function toReadableTime(given) {
var time = given;
var minutes = "0" + Math.floor(time / 60);
var seconds = "0" + (time - minutes * 60);
return minutes.substr(-2) + ":" + seconds.substr(-2);
}
const current = Math.floor(queue.connection.dispatcher.streamTime / 1000) //ms --> seconds
const end = track.duration //video in seconds
const value = (current * (100 / end) / 5)
bar.default.full = "█";
bar.default.empty = " - ";
bar.default.start = "";
bar.default.end = "";
bar.default.text = "{bar}";
let npEmbed = new MessageEmbed()
.setColor(ee.color)
.setFooter(ee.footertext)
.setTitle(`:musical_note: ${track.name}`)
.setURL(track.url)
.setThumbnail(track.thumbnail)
.addField("Views", `:eye: \`${track.views}\``, true)
.addField("Likes", `:thumbsup: \`${track.likes}\``, true)
.addField("Dislikes", `:thumbsdown: \`${track.dislikes}\``, true)
.addField("Voice Channel", `<#${message.guild.me.voice.channel.id}>`, true)
.addField("By", `${track.channelName}`, true)
.addField('Play/Resume', client.distube.isPaused(message) === true ? "▶" : "⏸", true)
.addField("Duration: ", `${toReadableTime(current)} - [${bar.progress(20, value)}] - ${track.formattedDuration}`)
message.channel.send(npEmbed)
message.delete();
} catch (e) {
errorbuilder(e, message)
}
}
}
possibly useful information
Discord.js version: 12.5.3 Distube version: 2.8.15 Stylish-text version: 1.1.3
I am not sure, what channelName
is, I cant find it anywhere in your track information
change this line:
.addField("By", `${track.channelName}`, true) //change this
.addField("By", `${track.name.split(" - ")[0]}`, true) //to this
NOTE: If every song you play as the artists name infront of the songs name, seperated with a
-
this should work all the time.
alternatively you could just set the name, of the youtube channel there like this:
.addField("By", `${track.info.videoDetails.ownerChannelName}`, true)