Skip to content

Commit

Permalink
[Enhancement] music embeds are now sent through the player events
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Nov 26, 2021
1 parent 063bb47 commit c9eda8f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 62 deletions.
4 changes: 2 additions & 2 deletions commands/Music/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
try {
if (queue) {
await queue.connection.disconnect();
await message.channel.send({
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
Expand All @@ -63,7 +63,7 @@ module.exports = {
}
} catch (err) {
client.logger(err.message, "error");
await message.channel.send({
return await message.channel.send({
embeds: [
embedMessage(
"RED",
Expand Down
57 changes: 1 addition & 56 deletions modules/Music.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,57 +96,9 @@ class Music {
? queue.addTracks(searchSong.tracks)
: queue.addTrack(searchSong.tracks[0]);

const username = command.member.user.username
? command.member.user.username
: command.user.username;

const avatar = command.member.user.avatarURL()
? command.member.user.avatarURL()
: command.user.avatarURL();

const musicEmbed = {
color: "#9dcc37",
title: `${queue.playing ? "✅ Added to Queue" : "🎵 Playing"}`,
author: {
name: `${username}`,
icon_url: `${avatar || client.user.avatarURL()}`,
},
description: `Song: **[${searchSong.tracks[0].title}](${searchSong.tracks[0].url})**`,
thumbnail: {
url: `${searchSong.tracks[0].thumbnail}`,
},
fields: [
{
name: "Author",
value: `${searchSong.tracks[0].author}`,
inline: true,
},
{
name: "🕓 Duration",
value: `${searchSong.tracks[0].duration}`,
inline: true,
},
],

timestamp: new Date(),
};

let playlistEmbed = {
color: "#9dcc37",
description: `✅ | Queued ${queue.tracks.length} Songs`,
};

if (!queue.playing) {
try {
await queue.play();
searchSong.playlist
? await command.reply({
embeds: [playlistEmbed, musicEmbed],
})
: await command.reply({
embeds: [musicEmbed],
});
return;
return await queue.play();
} catch (err) {
logger(err.message, "error");
console.log(err);
Expand All @@ -160,13 +112,6 @@ class Music {
});
}
}

if (queue.playing) {
searchSong.playlist
? await command.reply({ embeds: [playlistEmbed, musicEmbed] })
: await command.reply({ embeds: [musicEmbed] });
return;
}
}
}

Expand Down
46 changes: 42 additions & 4 deletions playerEvents/player.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { embedMessage } = require("../modules/embedSimple");
const { logger } = require("../modules/logger");
const { MessageActionRow, MessageButton } = require("discord.js");

module.exports.playerEvents = (player) => {
player.on("error", (queue, error) => {
Expand All @@ -12,7 +13,7 @@ module.exports.playerEvents = (player) => {
logger(
`${queue.guild.name}: Voice channel is empty right now!, leaving the Channel`
);
await queue.metadata.channel.channel.send({
return await queue.metadata.channel.channel.send({
embeds: [
embedMessage(
"9dcc37",
Expand All @@ -34,18 +35,55 @@ module.exports.playerEvents = (player) => {
player.on("queueEnd", (queue) => {
logger(`${queue.guild.name}: Queue has finished playing!`);
});
player.on("trackAdd", (queue, track) => {
player.on("trackAdd", async (queue, track) => {
logger(`${queue.guild.name}: ${track.title} has been added!`);

const musicEmbed = {
color: "#9dcc37",
title: `${queue.playing ? "✅ Added to Queue" : "🎵 Playing"}`,
description: `Song: **[${track.title}](${track.url})**`,
thumbnail: {
url: `${track.thumbnail}`,
},
fields: [
{
name: "Author",
value: `${track.author}`,
inline: true,
},
{
name: "🕓 Duration",
value: `${track.duration}`,
inline: true,
},
],

timestamp: new Date(),
};

return await queue.metadata.channel.reply({ embeds: [musicEmbed] });
});
player.on("trackEnd", (queue, track) => {
logger(`${queue.guild.name}: ${track.title} has finished playing!`);
});
player.on("tracksAdd", (queue, tracks) => {
player.on("tracksAdd", async (queue, tracks) => {
logger(
`${queue.guild.name}: A playlist with ${tracks.length} songs has beed added!`
);

let playlistEmbed = {
color: "#9dcc37",
description: `✅ | ${queue.playing ? "Queued" : "Added"} \`${
tracks.length
}\` Songs from [${tracks[0].playlist.title}](${tracks[0].playlist.url})`,
};

return await queue.metadata.channel.reply({
embeds: [playlistEmbed],
});
});
player.on("trackStart", (queue, track) => {

player.on("trackStart", async (queue, track) => {
logger(`${queue.guild.name}: ${track.title} has started playing`);
});
};

0 comments on commit c9eda8f

Please sign in to comment.