Advertisement
spiralvibes

Made By ZayDocs | CubeCloud Team

Nov 11th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Phone = require(`${process.cwd()}/src/database/GlobalChat.js`);
  2.  
  3. client.on("messageCreate", async (message) => {
  4.     if (message.guild === null || message.author.bot) return;
  5.  
  6.     const phonedata = await Phone.findOne({ Guild: message.guild.id });
  7.     if (!phonedata) return;
  8.  
  9.     const phonechannel = client.channels.cache.get(phonedata.Channel);
  10.     if (!phonechannel || phonechannel.id !== message.channel.id) return;
  11.  
  12.     const multidata = await Phone.find({ Setup: "defined" });
  13.  
  14.     await Promise.all(
  15.         multidata.map(async (data) => {
  16.             const targetChannel = await client.channels.fetch(data.Channel);
  17.             if (message.channel.id === targetChannel.id) return;
  18.  
  19.             const formattedMessage = message.content || "**No message provided!**";
  20.             const imageAttachments = message.attachments.size > 0 ? message.attachments.first().url : null;
  21.  
  22.             const userBadge = await getUserBadge(message.author.id);
  23.             const userDisplayName = `${userBadge.icon} ${userBadge.name} | ${message.author.tag}`;
  24.  
  25.             const chatEmbed = new EmbedBuilder()
  26.                 .setColor("#3498db")
  27.                 .setFooter({ text: `📬 Message from: ${message.guild.name.slice(0, 180)}` })
  28.                 .setAuthor({ name: `📱 Global Chat System`, iconURL: message.author.displayAvatarURL() })
  29.                 .setTimestamp()
  30.                 .setTitle(userDisplayName)
  31.                 .setDescription(formattedMessage.slice(0, 4000))
  32.                 .setThumbnail(message.author.displayAvatarURL({ dynamic: true }));
  33.  
  34.             if (imageAttachments) {
  35.                 chatEmbed.setImage(imageAttachments);
  36.             }
  37.  
  38.             await targetChannel.send({ embeds: [chatEmbed] }).catch(() => {
  39.                 message.reply("❌ An error occurred while trying to send your message. Please try again later.");
  40.             });
  41.         })
  42.     );
  43. });
  44.  
  45. async function getUserBadge(userId) {
  46.     const userBadges = [];
  47.  
  48.     if (userId === "299729731237052417") {
  49.         return { name: "👑 CC Owner", icon: "👑" };
  50.     }
  51.     if (userId === "909515934400643112") {
  52.         return { name: "🛠️ CC Developer", icon: "🛠️" };
  53.     }
  54.  
  55.     const guilds = client.guilds.cache.values();
  56.     for (const guild of guilds) {
  57.         const member = await guild.members.fetch(userId).catch(() => null);
  58.         if (member) {
  59.             if (member.roles.cache.has("1202408787810459657")) {
  60.                 return { name: "🟦 CubeCloud Member", icon: "🟦" };
  61.             } else if (member.roles.cache.has("1202408787877826593")) {
  62.                 return { name: "👨‍💻 Staff", icon: "👨‍💻" };
  63.             } else if (member.roles.cache.has("1202408787764449350")) {
  64.                 return { name: "👥 CC Member", icon: "👥" };
  65.             }
  66.         }
  67.     }
  68.  
  69.     return { name: "👤 CC Guest", icon: "👤" };
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement