const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"); const fs = require("fs"); module.exports = async function sendInitialMessage(client) { const roles = [ { id: "1256896760245129331", label: "Yayin duyuru", }, { id: "1256898220307779664", label: "Sunucu onay", }, ]; let status = JSON.parse(fs.readFileSync("status.json", "utf8")); try { const channel = await client.channels.cache.get("1255376424743862294"); if (!channel) { console.error("Channel not found"); return; } const row = new ActionRowBuilder().addComponents( roles.map((role) => new ButtonBuilder() .setCustomId(role.id) .setLabel(role.label) .setStyle(ButtonStyle.Primary) ) ); client.on("interactionCreate", async (interaction) => { if (!interaction.isButton) await interaction.deferReply({ ephemeral: true }); const role = interaction.guild.roles.cache.get(interaction.customId); if (!role) { interaction.editReply({ content: "Role doesn't exist", }); return; } const hasRole = interaction.member.roles.cache.has(role.id); if (hasRole) { await interaction.member.roles.remove(role); await interaction.editReply( `the role ${role} has been removed from ${interaction.user}` ); return; } await interaction.member.roles.add(role); await interaction.editReply( `the role ${role} has been given to ${interaction.user}` ); }); if (status.initialMessageSent) { console.log("Initial message already sent. Skipping..."); return; } else { await channel.send({ content: "Claim or Remove a role below", components: [row], }); } console.log("Initial message sent successfully."); status.initialMessageSent = true; fs.writeFileSync("status.json", JSON.stringify(status)); } catch (error) { console.log(`Error in ${__filename}:\n`, error); } };