first commit

This commit is contained in:
2025-06-21 15:13:58 -05:00
commit 07f75bbd93
37 changed files with 3125 additions and 0 deletions

132
commands/music/bplay.js Normal file
View File

@ -0,0 +1,132 @@
const { Client, Interaction, SlashCommandBuilder, VoiceChannel } = require('discord.js');
const { playFromQueue, queue} = require('../../playback');
const ytdl = require('ytdl-core');
const { default: axios } = require('axios');
const { setStopped, cancelTimer } = require('../../playback')
var isDisabled = false
const API_KEY = process.env.YoutubeToken
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
async function addToQueue(interaction, link, songName) {
const voiceChannel = interaction.member.voice.channel;
const textChannel = interaction.channel;
const getMember = interaction.member.displayName;
const wasQueueEmpty = queue.length === 0;
queue.push({interaction, getMember, link, songName})
cancelTimer()
if (wasQueueEmpty) {
await playFromQueue(voiceChannel, textChannel, getMember, link, songName)
} else {
//console.log(queue)
interaction.reply(`Added to queue: ${songName}`)
}
}
async function searchYoutubeSong(input) {
try {
const response = await axios.get('https://www.googleapis.com/youtube/v3/search', {
params: {
part: 'snippet',
q: input,
key: API_KEY,
maxResults: 1,
type: 'video',
}
});
if (response.data.items && response.data.items.length > 0) {
const video = response.data.items[0];
const videoId = video.id.videoId;
const videoTitle = video.snippet.title;
const videoUrl = `https://www.youtube.com/watch?v=${videoId}`;
return { videoUrl, videoTitle}
} else {
return null;
}
} catch (error) {
console.error('Error searching Youtube: ', error)
return null;
}
}
async function handlePlayCommand(interaction, input) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply({
content: 'You need to be in a voice channel to use this command.',
ephemeral: true
});
}
try {
let link = '';
let songName = input;
if (ytdl.validateURL(input)) {
// If it's a valid YouTube URL, extract the song information
const videoInfo = await ytdl.getBasicInfo(input);
songName = videoInfo.videoDetails.title;
link = input;
} else {
// If it's a search query, find the video
const searchResult = await searchYoutubeSong(input);
if (searchResult) {
link = searchResult.videoUrl;
songName = searchResult.videoTitle;
} else {
return interaction.reply({
content: 'No results found for your query.',
ephemeral: true,
});
}
}
// Add the song to the queue and play if needed
await addToQueue(interaction, link, songName);
} catch (error) {
console.error('Error handling play command:', error);
await interaction.reply({
content: 'An error occurred while processing your request.',
ephemeral: true,
});
}
}
module.exports = {
data: new SlashCommandBuilder()
.setName('bplay')
.setDescription('Plays a song')
.addStringOption(option =>
option.setName('query')
.setDescription('The song name or URL to play')
.setRequired(true)
),
async execute(interaction) {
try {
if (isDisabled) return interaction.reply({ content: 'The command is Disabled... Try again later', ephemeral: true})
const query = interaction.options.getString('query');
setStopped(false)
await handlePlayCommand(interaction, query);
} catch (error) {
console.error('Error executing play command:', error);
await interaction.reply({
content: 'An error occurred while processing your request.',
ephemeral: true
});
}
}
};

36
commands/music/queue.js Normal file
View File

@ -0,0 +1,36 @@
const { Client, Interaction, SlashCommandBuilder, EmbedBuilder } = require('discord.js')
const { queue } = require('./../../playback')
const { musicQueueEmbed } = require('../../embeds/queue');
async function checkQueue(interaction) {
if (!queue || queue.length === 0 ) {
interaction.reply('The queue is empty.')
return
}
try {
const embed = musicQueueEmbed(queue);
await interaction.reply({ embeds: [embed] })
} catch (error) {
console.log('There is an error in the queue command: ', error)
}
}
module.exports = {
data: new SlashCommandBuilder()
.setName('queue')
.setDescription('Check the playback queue'),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel
const textChannel = interaction.textChannel
if (!voiceChannel) {
return interaction.reply({
content: 'You need to be in a voice channel to use that queue',
ephemeral: true
})
}
await checkQueue(interaction, voiceChannel, textChannel)
}
}

60
commands/music/skip.js Normal file
View File

@ -0,0 +1,60 @@
const { Client, Interaction, SlashCommandBuilder } = require('discord.js')
const { playFromQueue, queue } = require('../../playback');
const { getVoiceConnection } = require('@discordjs/voice')
async function skipSong(voiceChannel, textChannel) {
const connection = getVoiceConnection(voiceChannel.guild.id)
if (!connection) {
console.log('No active voice connections')
textChannel.send('No active voice connections')
return
}
if (!queue || queue.length === 0) {
console.log('Queue is empty. No songs to skip')
connection.state.subscription.player.stop();
return;
}
try {
queue.shift()
if (queue.length > 0 ) {
const nextSong = queue[0];
await playFromQueue(voiceChannel, textChannel, nextSong.getMember, nextSong.link, nextSong.songName)
} else {
textChannel.send('No more songs in the queue')
}
} catch (error) {
console.error('Error skipping song: ', error)
}
}
module.exports = {
data: new SlashCommandBuilder()
.setName('skip')
.setDescription('Skips a song in the queue'),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel
const textChannel = interaction.channel
if (!voiceChannel) {
return interaction.reply({
content: 'You need to be in a voice channel to use the command',
ephemeral: true
});
}
try {
await skipSong(voiceChannel, textChannel)
interaction.reply('Skipped the current song')
} catch (error) {
console.error('Error in skip command: ', error)
interaction.reply({
content: 'An error has occurred while processing the command',
ephemeral: true
});
}
}
}

20
commands/music/stop.js Normal file
View File

@ -0,0 +1,20 @@
const { SlashCommandBuilder } = require("discord.js");
const { resetAll, setStopped } = require("../../playback");
module.exports = {
data: new SlashCommandBuilder()
.setName("stop")
.setDescription("Stop playback and leave the voice channel"),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply({ content: "You need to be in a voice channel to use this command.", ephemeral: true });
}
setStopped(true); // Mark playback as stopped
resetAll(voiceChannel.guild.id); // Reset everything for a clean state
return interaction.reply("Stopped playback and left the voice channel.");
},
};