Skip to content

Commit

Permalink
FEAT: close to finishing music management, UP version
Browse files Browse the repository at this point in the history
  • Loading branch information
UsrBinLuna committed Jun 11, 2024
1 parent 26a09c6 commit ec70a5b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 19 deletions.
58 changes: 58 additions & 0 deletions commands/music/music.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonStyle, ButtonBuilder, ComponentType } = require('discord.js');
const { useMainPlayer, useQueue } = require('discord-player');

module.exports = {
data: new SlashCommandBuilder()
.setName('music')
.setDescription('Music manager dashboard'),
async execute(interaction) {

const player = useMainPlayer();
const channel = interaction.member.voice.channelId;
const queue = useQueue(interaction.guild.id);
const currentTrack = queue.currentTrack;
const tracksArray = queue.tracks.toArray();
if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel

const playPause = new ButtonBuilder()
.setCustomId('playpause')
.setLabel('⏯')
.setStyle(ButtonStyle.Primary);

const skip = new ButtonBuilder()
.setCustomId('skip')
.setLabel('⏭')
.setStyle(ButtonStyle.Secondary);

const clear = new ButtonBuilder()
.setCustomId('clear')
.setLabel('❌')
.setStyle(ButtonStyle.Danger);


const row = new ActionRowBuilder()
.addComponents(playPause, skip, clear);

const embed = new EmbedBuilder();

embed
.setTitle(`${currentTrack}`)
.setDescription(`Next track: ${tracksArray[0]}`)
.setThumbnail(`${currentTrack.thumbnail}`)
.addFields({ name: `Duration:`, value: `${currentTrack.duration}`, inline: true },
{ name: 'Songs left:', value: `${queue.getSize()}`, inline: true }
);


const reply = await interaction.reply({
content: `_ _`,
embeds: [embed],
components: [row],
});

const collector = reply.createMessageComponentCollector({ componentType: ComponentType.StringSelect, time: 3_600_000 });

const collectorFilter = i => i.user.id === interaction.user.id;

},
};
4 changes: 2 additions & 2 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module.exports = {
.setTitle(`Added to queue`)
.setColor('#00FFFF')
.setThumbnail(track.thumbnail)
.setDescription(`${track.author} - **${track.title}**\nDuration: ${track.duration}`)
.setFooter({ text: `Requested by ${username}, ${track.url}` });
.setDescription(`**${track.title}**\nDuration: ${track.duration}`)
.setFooter({ text: `Requested by ${username}` });

return interaction.followUp({ embeds: [embed] });
} catch (e) {
Expand Down
36 changes: 36 additions & 0 deletions events/helper/buttonIdHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function buttonIdHandler(id, msg) {

const { useMainPlayer, useQueue } = require('discord-player');
const { guildId } = require('../../config.json');
const queue = useQueue(guildId);
const currentTrack = queue.currentTrack;

switch(id) {
case "playpause":
queue.node.setPaused(!queue.node.isPaused());
if (!queue.node.isPaused()) {
msg.edit(`Resuming **${currentTrack}**`);
} else {
msg.edit(`Paused player`);
}
break;

case "skip":
msg.edit(`Skipping **${currentTrack}**`)
queue.node.skip();
break;

case "clear":
msg.delete();
break;

default:
msg.edit(`**Achievement get:** How did we get here?\nSeriously how did you get an invalid ID`);

}

}

module.exports = {
buttonIdHandler,
};
39 changes: 24 additions & 15 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,35 @@ const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,


async execute(interaction) {
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);
const { buttonIdHandler } = require('./helper/buttonIdHandler');

if (!command) {
console.error(`No command matching '${interaction.commandName}' was found.`);
await interaction.reply({ content: `No command matching '${interaction.commandName}' was found.`, ephemeral: true });
return;
}
if (interaction.isChatInputCommand()){

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching '${interaction.commandName}' was found.`);
await interaction.reply({ content: `No command matching '${interaction.commandName}' was found.`, ephemeral: true });
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
} else if (interaction.isButton()) {
// Permanent button menus
buttonIdHandler(interaction.customId, interaction.message)
}
},
};
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { REST } = require("@discordjs/rest");
const { Client, Collection, GatewayIntentBits, EmbedBuilder, ActivityType } = require("discord.js");
const { token } = require('./config.json');
const { Player } = require('discord-player');
const { version } = require('./package.json');

const fs = require("fs");
const path = require('node:path');
Expand Down Expand Up @@ -39,7 +40,7 @@ client.on("ready", () => {

const channel = client.channels.cache.get('1231228286148018321');
if (channel) {
channel.send('Working');
channel.send(`# Welcome to Mao Zedong v${version}`);
} else {
console.error('Could not find the specified channel.');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mao",
"version": "20240430.01",
"version": "0.5.69-beta",
"description": "Mao Zedong bot",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ec70a5b

Please sign in to comment.