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ilder, Events } = require('discord.js')
|
| 3 |
+
const axios = require('axios')
|
| 4 |
+
|
| 5 |
+
const TOKEN = process.env.DISCORD_TOKEN || "MTM4ODgwMjQ0OTQ5MzcyMTIxOA.G3-WAQ.VIESW3luPp36L5zP6VcsT0Ssjjc8xufThvSn4U"
|
| 6 |
+
const CLIENT_ID = process.env.CLIENT_ID || "1388802449493721218"
|
| 7 |
+
const GUILD_ID = process.env.GUILD_ID || "1388777582975254659"
|
| 8 |
+
|
| 9 |
+
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] })
|
| 10 |
+
|
| 11 |
+
const rest = new REST({ version: '10' }).setToken(TOKEN)
|
| 12 |
+
|
| 13 |
+
const commands = [
|
| 14 |
+
{
|
| 15 |
+
name: 'uploadsong',
|
| 16 |
+
description: 'Upload a song from a YouTube URL',
|
| 17 |
+
options: [
|
| 18 |
+
{
|
| 19 |
+
name: 'url',
|
| 20 |
+
type: 3,
|
| 21 |
+
description: 'YouTube URL',
|
| 22 |
+
required: true
|
| 23 |
+
}
|
| 24 |
+
]
|
| 25 |
+
}
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
const cooldowns = new Map()
|
| 29 |
+
|
| 30 |
+
async function registerCommands() {
|
| 31 |
+
try {
|
| 32 |
+
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands })
|
| 33 |
+
console.log('Slash commands registered')
|
| 34 |
+
} catch (error) {
|
| 35 |
+
console.error('Failed to register slash commands:', error)
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
client.on(Events.MessageCreate, async (message) => {
|
| 40 |
+
if (message.author.bot || !message.mentions.has(client.user)) return
|
| 41 |
+
const args = message.content.trim().split(/\s+/)
|
| 42 |
+
if (!args[1] || args[1].toLowerCase() !== 'uploadsong' || !args[2]) return
|
| 43 |
+
const yturl = args[2]
|
| 44 |
+
const uid = message.author.id
|
| 45 |
+
const name = message.author.username
|
| 46 |
+
const pic = message.author.displayAvatarURL()
|
| 47 |
+
|
| 48 |
+
if (cooldowns.has(uid)) {
|
| 49 |
+
const remaining = Math.ceil((cooldowns.get(uid) - Date.now()) / 1000)
|
| 50 |
+
if (remaining > 0) {
|
| 51 |
+
const cooldownEmbed = new EmbedBuilder()
|
| 52 |
+
.setTitle('β³ Cooldown')
|
| 53 |
+
.setDescription(`Please wait **${remaining}s** before using this command again.`)
|
| 54 |
+
.setColor('Orange')
|
| 55 |
+
return message.reply({ embeds: [cooldownEmbed] })
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
cooldowns.set(uid, Date.now() + 60000)
|
| 60 |
+
|
| 61 |
+
const embed = new EmbedBuilder()
|
| 62 |
+
.setTitle('β±οΈ Reuploading song')
|
| 63 |
+
.setDescription('π₯ Please wait while we upload the song.')
|
| 64 |
+
.setColor('Yellow')
|
| 65 |
+
|
| 66 |
+
const sent = await message.reply({ embeds: [embed] })
|
| 67 |
+
|
| 68 |
+
try {
|
| 69 |
+
const res = await axios.get(`https://jonell01-reuploadotherhruhh.hf.space/addsong?url=${encodeURIComponent(yturl)}`)
|
| 70 |
+
if (res.data.success) {
|
| 71 |
+
const song = res.data.song
|
| 72 |
+
const success = new EmbedBuilder()
|
| 73 |
+
.setTitle(`β
Reupload Song Successfully`)
|
| 74 |
+
.setDescription(`π΅ **Song Title:** ${song.name}\nπ **ID:** ${song.ID}\n<:folder:1333485662149545994> **Size:** ${song.size} MB`)
|
| 75 |
+
.setFooter({ text: `π§ Reuploaded song by : ${name}`, iconURL: pic })
|
| 76 |
+
.setColor('Green')
|
| 77 |
+
await sent.edit({ embeds: [success] })
|
| 78 |
+
} else {
|
| 79 |
+
throw new Error()
|
| 80 |
+
}
|
| 81 |
+
} catch {
|
| 82 |
+
const fail = new EmbedBuilder()
|
| 83 |
+
.setTitle('β Upload Failed')
|
| 84 |
+
.setDescription('An error occurred while uploading.')
|
| 85 |
+
.setColor('Red')
|
| 86 |
+
await sent.edit({ embeds: [fail] })
|
| 87 |
+
}
|
| 88 |
+
})
|
| 89 |
+
|
| 90 |
+
client.on(Events.InteractionCreate, async (interaction) => {
|
| 91 |
+
if (!interaction.isChatInputCommand()) return
|
| 92 |
+
if (interaction.commandName === 'uploadsong') {
|
| 93 |
+
const uid = interaction.user.id
|
| 94 |
+
const name = interaction.user.username
|
| 95 |
+
const pic = interaction.user.displayAvatarURL()
|
| 96 |
+
|
| 97 |
+
if (cooldowns.has(uid)) {
|
| 98 |
+
const remaining = Math.ceil((cooldowns.get(uid) - Date.now()) / 1000)
|
| 99 |
+
if (remaining > 0) {
|
| 100 |
+
const cooldownEmbed = new EmbedBuilder()
|
| 101 |
+
.setTitle('β³ Cooldown')
|
| 102 |
+
.setDescription(`Please wait **${remaining}s** before using this command again.`)
|
| 103 |
+
.setColor('Orange')
|
| 104 |
+
return interaction.reply({ embeds: [cooldownEmbed], ephemeral: true })
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
cooldowns.set(uid, Date.now() + 60000)
|
| 109 |
+
const yturl = interaction.options.getString('url')
|
| 110 |
+
const embed = new EmbedBuilder()
|
| 111 |
+
.setTitle('β±οΈ Reuploading song')
|
| 112 |
+
.setDescription('π₯ Please wait while we upload the song.')
|
| 113 |
+
.setColor('Yellow')
|
| 114 |
+
|
| 115 |
+
await interaction.reply({ embeds: [embed], fetchReply: true }).then(async (sent) => {
|
| 116 |
+
try {
|
| 117 |
+
const res = await axios.get(`https://jonell01-reuploadotherhruhh.hf.space/addsong?url=${encodeURIComponent(yturl)}`)
|
| 118 |
+
if (res.data.success) {
|
| 119 |
+
const song = res.data.song
|
| 120 |
+
const success = new EmbedBuilder()
|
| 121 |
+
.setTitle(`β
Reupload Song Successfully`)
|
| 122 |
+
.setDescription(`π΅ **Song Title:** ${song.name}\nπ **ID:** ${song.ID}\n<:folder:1333485662149545994> **Size:** ${song.size} MB`)
|
| 123 |
+
.setFooter({ text: `π§ Reuploaded song by : ${name}`, iconURL: pic })
|
| 124 |
+
.setColor('Green')
|
| 125 |
+
await interaction.editReply({ embeds: [success] })
|
| 126 |
+
} else {
|
| 127 |
+
throw new Error()
|
| 128 |
+
}
|
| 129 |
+
} catch {
|
| 130 |
+
const fail = new EmbedBuilder()
|
| 131 |
+
.setTitle('β Upload Failed')
|
| 132 |
+
.setDescription('An error occurred while uploading.')
|
| 133 |
+
.setColor('Red')
|
| 134 |
+
await interaction.editReply({ embeds: [fail] })
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
}
|
| 138 |
+
})
|
| 139 |
+
|
| 140 |
+
client.once(Events.ClientReady, () => {
|
| 141 |
+
console.log(`β
Logged in as ${client.user.tag}`)
|
| 142 |
+
})
|
| 143 |
+
|
| 144 |
+
client.on('error', (err) => {
|
| 145 |
+
console.error('β Bot connection error:', err)
|
| 146 |
+
})
|
| 147 |
+
|
| 148 |
+
registerCommands()
|
| 149 |
+
client.login(TOKEN).catch((err) => {
|
| 150 |
+
console.error('β Failed to login:', err)
|
| 151 |
+
})
|