const Buyer = require("./Schemas/buyerSchema"); const ticket = require('./Schemas/ticketSchema'); let buyerIdStore = {}; // Penyimpanan informasi interaksi client.on('messageCreate', async message => { if (message.channel.id !== '1229478031182135397') { return; } if (!message.author.bot && message.content.toLowerCase().trim() === 'buy') { await message.author.send("Kamu salah input!"); } else if (!message.author.bot && message.content.toLowerCase().includes('buy')) { const user = message.author; const buyItem = message.content.substring(5).trim(); // Ubah menjadi 5 agar memotong kata 'buy' const userStrings = user.username; // Cek apakah ID pembeli sudah ada sebelumnya const existingBuyer = await Buyer.findOne({ userId: user.id }); if (existingBuyer) { console.log('Buyer ID already exists in the database:', user.id); } else { // Simpan ID pembeli ke MongoDB jika belum ada sebelumnya const newBuyer = new Buyer({ userId: user.id }); await newBuyer.save(); console.log('Buyer ID successfully saved to the database:', user.id); } // Mengirim pesan ke pengguna dengan informasi pembelian const file = new AttachmentBuilder('/home/joblow/Desktop/Bot-Discord/src/gambar/jgrp.png'); const embed = new EmbedBuilder() .setTitle(`${userStrings}`) .setDescription(`${buyItem}`); // Pastikan deskripsi tidak kosong const buttonSell = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId('buy_button') .setLabel('📥') .setStyle(ButtonStyle.Success), new ButtonBuilder() .setCustomId('keranjang_button') .setLabel('🛒') .setStyle(ButtonStyle.Primary), new ButtonBuilder() .setCustomId('delete_button') .setLabel('🗑️') .setStyle(ButtonStyle.Danger) ); await message.channel.send(`\`\`RTM\`\``, { ephemeral: true }); const sentMessage = await message.channel.send({ embeds: [embed], components: [buttonSell], files: [file], ephemeral: true }); // Hapus pesan asli yang memicu tanggapan bot setelah bot merespons if (message.deletable) { try { await message.delete(); } catch (error) { console.error('Error deleting message:', error); } } else { console.log('Message not deletable'); } } }); client.on('interactionCreate', async interaction => { if (!interaction.isButton()) return; const { customId, user, message } = interaction; if (customId === 'buy_button') { // Simpan informasi interaksi dari user yang mengklik tombol buyerIdStore[user.id] = { messageId: message.id }; const confirmationEmbed = new EmbedBuilder() .setTitle("Konfirmasi Pembuatan Tiket") .setDescription("Apakah Anda yakin ingin membuat tiket?\nPesan ini akan hilang dalam 10 detik!!!!") .setColor(0x800080); const buttonRow = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setLabel('yes') .setCustomId('yes_button') .setStyle(ButtonStyle.Success) ); const reply = await interaction.reply({ embeds: [confirmationEmbed], components: [buttonRow] }); // Hapus pesan setelah 10 detik setTimeout(async () => { await reply.delete(); }, 10000); } else if (customId === 'yes_button') { const { messageId } = buyerIdStore[user.id] || {}; // Hapus informasi interaksi yang sudah tidak diperlukan delete buyerIdStore[user.id]; // Dapatkan informasi pembelian dari pesan yang sebelumnya dikirimkan const message = await interaction.channel.messages.fetch(messageId); const buyer = message.author; const buyItem = message.content.substring(5).trim(); // Lakukan pembuatan tiket untuk pembeli dan pengguna yang mengklik tombol const buyerId = buyer.id; const data = await ticket.findOne({ Guild: interaction.guild.id }); if (!data) return await interaction.reply({ content: 'Sorry looks like you found this message but you have not setup the ticket', ephemeral: true }); const category = interaction.guild.channels.cache.get(data.Category); const channel = await interaction.guild.channels.create({ name: `ticket-${buyerId}`, type: ChannelType.GuildText, topic: `T`, parent: category, permissionOverwrites: [ { id: buyerId, allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory] }, { id: interaction.guild.roles.everyone.id, deny: [PermissionsBitField.Flags.ViewChannel] }, { id: interaction.user.id, allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory] }, ], }); const embed = new EmbedBuilder() .setTitle(`Ticket from ${buyerId} `) .setDescription(`Ini adalah embed`) .setTimestamp() .setThumbnail("https://i.postimg.cc/xdC3qtBw/Text-To-Image-25-20240405.png"); const button = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setEmoji({ name: '🔒' }) .setCustomId('closeTicket') .setLabel('Close Ticket') .setStyle(ButtonStyle.Danger), new ButtonBuilder() .setEmoji({ name: '📑' }) .setCustomId('Transcript') .setLabel('Transcript') .setStyle(ButtonStyle.Primary), new ButtonBuilder() .setEmoji({ name: '🔔' }) .setLabel('Ping Staff') // Tambahkan label di sini .setStyle(ButtonStyle.Secondary) .setCustomId('pingStaff') ); const select = new StringSelectMenuBuilder() .setCustomId('sekon') .setPlaceholder('Make a selection!') .addOptions( new StringSelectMenuOptionBuilder() .setLabel('Jasa Rekber') .setDescription('Untuk memesan Jasa Rekber') .setValue('jasa'), new StringSelectMenuOptionBuilder() .setLabel('Meminta Akses Menutup Tiket') .setDescription('Untuk akses menutup tiket') .setValue('aksesTutup'), ); const row = new ActionRowBuilder() .addComponents(select); await channel.send({ embeds: [embed], components: [button, row] }); await interaction.reply({ content: `Your ticket has been opened in ${channel}`, ephemeral: true }); } });