From 8e0e64976171f0489e5e9151a8c674fd7c869416 Mon Sep 17 00:00:00 2001 From: Zerio <43386412+ZerioDev@users.noreply.github.com> Date: Wed, 20 Oct 2021 21:56:18 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Save=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/music/nowplaying.js | 12 ++++++++++-- events/interactionCreate.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 events/interactionCreate.js diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js index b6765cb..75adcb5 100644 --- a/commands/music/nowplaying.js +++ b/commands/music/nowplaying.js @@ -1,4 +1,4 @@ -const { MessageEmbed } = require('discord.js'); +const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); module.exports = { name: 'nowplaying', @@ -29,6 +29,14 @@ module.exports = { embed.setTimestamp(); embed.setFooter('Music comes first - Made with heart by Zerio ❤️', message.author.avatarURL({ dynamic: true })); - message.channel.send({ embeds: [embed] }); + const saveButton = new MessageButton(); + + saveButton.setLabel('Save this track'); + saveButton.setCustomId('saveTrack'); + saveButton.setStyle('SUCCESS'); + + const row = new MessageActionRow().addComponents(saveButton); + + message.channel.send({ embeds: [embed], components: [row] }); }, }; \ No newline at end of file diff --git a/events/interactionCreate.js b/events/interactionCreate.js new file mode 100644 index 0000000..83b5169 --- /dev/null +++ b/events/interactionCreate.js @@ -0,0 +1,17 @@ +module.exports = (client, int) => { + if (!int.isButton()) return; + + const queue = player.getQueue(int.guildId); + + switch (int.customId) { + case 'saveTrack': { + if (!queue || !queue.playing) return int.reply({ content: `No music currently playing <@${int.user.id}>... try again ? ❌`, components: [] }); + + int.member.send(`You saved the track ${queue.current.title} | ${queue.current.author} from the server ${int.member.guild.name} ✅`).then(() => { + return int.reply({ content: `I have sent you the title of the music by private messages <@${int.user.id}> ✅`, components: [] }); + }).catch(error => { + return int.reply({ content: `Unable to send you a private message <@${int.user.id}>... try again ? ❌`, components: [] }); + }); + } + } +}; \ No newline at end of file