const Discord = require("discord.js"); const func = require("../../utils/functions"); const config = require("../../../config/config.json"); const commands = require("../../utils/commands.json"); module.exports = { name: "Announce", cooldown: 1, async execute(client, message, args, cmd) { if (message.author.id !== config.ownerId) return; await message.channel.sendTyping(); const { CloseButton, SupportButton } = require("../../utils/components"); const closeButton = Discord.ButtonBuilder.from(CloseButton).setCustomId(`messageDelete-${message.author.id}`); const closeRow = new Discord.ActionRowBuilder().addComponents([closeButton]); const supportRow = new Discord.ActionRowBuilder().addComponents([SupportButton]); const notifiedGuilds = []; const selectedGuilds = client.winnersGuild.cache; const sendingEmbed = new Discord.EmbedBuilder() .setColor("#ed165a") .setDescription(`Sending Message to ${guilds.size} Guilds in ${func.convertTime(guilds.size * 1000)}`); const msg = await message.reply({ embeds: [sendingEmbed], components: [closeRow] }); const embed = new Discord.EmbedBuilder() .setColor("#ed165a") .setAuthor({ name: "Test", iconURL: client.user.displayAvatarURL({ size: 1024 }) }) .setDescription(`Test 2`); const requriedPermissions = ["ViewChannel", "SendMessages", "EmbedLinks"]; for (const guild of selectedGuilds.values()) { const announceChannels = func.sortChannels( guild.channels.cache.filter( (channel) => channel.type === Discord.ChannelType.GuildText && channel.permissionsFor(guild.members.me).has(requriedPermissions) ) ); if (announceChannels) { const announceChannel = announceChannels.first(); if (announceChannel) { await announceChannel .send({ content: `<@${guild.ownerId}>`, embeds: [embed], components: [supportRow] }) .then(() => { notifiedGuilds.push(guild.id); }) .catch((err) => { console.log(err); }); } } await func.delay(1000); } sendingEmbed.setDescription(`Total Guilds: ${guilds.size} | Notified Guilds: ${notifiedGuilds.length} `); await msg.edit({ embeds: [sendingEmbed, embed] }); }, };