Spaces:
Paused
Paused
| require('dotenv').config() | |
| const { Client, GatewayIntentBits, REST, Routes, EmbedBuilder, Events } = require('discord.js') | |
| const axios = require('axios') | |
| const TOKEN = process.env.DISCORD_TOKEN || "MTM4ODgwMjQ0OTQ5MzcyMTIxOA.G3-WAQ.VIESW3luPp36L5zP6VcsT0Ssjjc8xufThvSn4U" | |
| const CLIENT_ID = process.env.CLIENT_ID || "1388802449493721218" | |
| const GUILD_ID = process.env.GUILD_ID || "1388777582975254659" | |
| const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }) | |
| const rest = new REST({ version: '10' }).setToken(TOKEN) | |
| const commands = [ | |
| { | |
| name: 'uploadsong', | |
| description: 'Upload a song from a YouTube URL', | |
| options: [ | |
| { | |
| name: 'url', | |
| type: 3, | |
| description: 'YouTube URL', | |
| required: true | |
| } | |
| ] | |
| } | |
| ] | |
| const cooldowns = new Map() | |
| async function registerCommands() { | |
| try { | |
| await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands }) | |
| console.log('Slash commands registered') | |
| } catch (error) { | |
| console.error('Failed to register slash commands:', error) | |
| } | |
| } | |
| client.on(Events.MessageCreate, async (message) => { | |
| if (message.author.bot || !message.mentions.has(client.user)) return | |
| const args = message.content.trim().split(/\s+/) | |
| if (!args[1] || args[1].toLowerCase() !== 'uploadsong' || !args[2]) return | |
| const yturl = args[2] | |
| const uid = message.author.id | |
| const name = message.author.username | |
| const pic = message.author.displayAvatarURL() | |
| if (cooldowns.has(uid)) { | |
| const remaining = Math.ceil((cooldowns.get(uid) - Date.now()) / 1000) | |
| if (remaining > 0) { | |
| const cooldownEmbed = new EmbedBuilder() | |
| .setTitle('β³ Cooldown') | |
| .setDescription(`Please wait **${remaining}s** before using this command again.`) | |
| .setColor('Orange') | |
| return message.reply({ embeds: [cooldownEmbed] }) | |
| } | |
| } | |
| cooldowns.set(uid, Date.now() + 60000) | |
| const embed = new EmbedBuilder() | |
| .setTitle('β±οΈ Reuploading song') | |
| .setDescription('π₯ Please wait while we upload the song.') | |
| .setColor('Yellow') | |
| const sent = await message.reply({ embeds: [embed] }) | |
| try { | |
| const res = await axios.get(`https://jonell01-reuploadotherhruhh.hf.space/addsong?url=${encodeURIComponent(yturl)}`) | |
| if (res.data.success) { | |
| const song = res.data.song | |
| const success = new EmbedBuilder() | |
| .setTitle(`β Reupload Song Successfully`) | |
| .setDescription(`π΅ **Song Title:** ${song.name}\nπ **ID:** ${song.ID}\n<:folder:1333485662149545994> **Size:** ${song.size} MB`) | |
| .setFooter({ text: `π§ Reuploaded song by : ${name}`, iconURL: pic }) | |
| .setColor('Green') | |
| await sent.edit({ embeds: [success] }) | |
| } else { | |
| throw new Error() | |
| } | |
| } catch { | |
| const fail = new EmbedBuilder() | |
| .setTitle('β Upload Failed') | |
| .setDescription('An error occurred while uploading.') | |
| .setColor('Red') | |
| await sent.edit({ embeds: [fail] }) | |
| } | |
| }) | |
| client.on(Events.InteractionCreate, async (interaction) => { | |
| if (!interaction.isChatInputCommand()) return | |
| if (interaction.commandName === 'uploadsong') { | |
| const uid = interaction.user.id | |
| const name = interaction.user.username | |
| const pic = interaction.user.displayAvatarURL() | |
| if (cooldowns.has(uid)) { | |
| const remaining = Math.ceil((cooldowns.get(uid) - Date.now()) / 1000) | |
| if (remaining > 0) { | |
| const cooldownEmbed = new EmbedBuilder() | |
| .setTitle('β³ Cooldown') | |
| .setDescription(`Please wait **${remaining}s** before using this command again.`) | |
| .setColor('Orange') | |
| return interaction.reply({ embeds: [cooldownEmbed], ephemeral: true }) | |
| } | |
| } | |
| cooldowns.set(uid, Date.now() + 60000) | |
| const yturl = interaction.options.getString('url') | |
| const embed = new EmbedBuilder() | |
| .setTitle('β±οΈ Reuploading song') | |
| .setDescription('π₯ Please wait while we upload the song.') | |
| .setColor('Yellow') | |
| await interaction.reply({ embeds: [embed], fetchReply: true }).then(async (sent) => { | |
| try { | |
| const res = await axios.get(`https://jonell01-reuploadotherhruhh.hf.space/addsong?url=${encodeURIComponent(yturl)}`) | |
| if (res.data.success) { | |
| const song = res.data.song | |
| const success = new EmbedBuilder() | |
| .setTitle(`β Reupload Song Successfully`) | |
| .setDescription(`π΅ **Song Title:** ${song.name}\nπ **ID:** ${song.ID}\n<:folder:1333485662149545994> **Size:** ${song.size} MB`) | |
| .setFooter({ text: `π§ Reuploaded song by : ${name}`, iconURL: pic }) | |
| .setColor('Green') | |
| await interaction.editReply({ embeds: [success] }) | |
| } else { | |
| throw new Error() | |
| } | |
| } catch { | |
| const fail = new EmbedBuilder() | |
| .setTitle('β Upload Failed') | |
| .setDescription('An error occurred while uploading.') | |
| .setColor('Red') | |
| await interaction.editReply({ embeds: [fail] }) | |
| } | |
| }) | |
| } | |
| }) | |
| client.once(Events.ClientReady, () => { | |
| console.log(`β Logged in as ${client.user.tag}`) | |
| }) | |
| client.on('error', (err) => { | |
| console.error('β Bot connection error:', err) | |
| }) | |
| registerCommands() | |
| client.login(TOKEN).catch((err) => { | |
| console.error('β Failed to login:', err) | |
| }) |