Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Phone = require(`${process.cwd()}/src/database/GlobalChat.js`);
- client.on("messageCreate", async (message) => {
- if (message.guild === null || message.author.bot) return;
- const phonedata = await Phone.findOne({ Guild: message.guild.id });
- if (!phonedata) return;
- const phonechannel = client.channels.cache.get(phonedata.Channel);
- if (!phonechannel || phonechannel.id !== message.channel.id) return;
- const multidata = await Phone.find({ Setup: "defined" });
- await Promise.all(
- multidata.map(async (data) => {
- const targetChannel = await client.channels.fetch(data.Channel);
- if (message.channel.id === targetChannel.id) return;
- const formattedMessage = message.content || "**No message provided!**";
- const imageAttachments = message.attachments.size > 0 ? message.attachments.first().url : null;
- const userBadge = await getUserBadge(message.author.id);
- const userDisplayName = `${userBadge.icon} ${userBadge.name} | ${message.author.tag}`;
- const chatEmbed = new EmbedBuilder()
- .setColor("#3498db")
- .setFooter({ text: `📬 Message from: ${message.guild.name.slice(0, 180)}` })
- .setAuthor({ name: `📱 Global Chat System`, iconURL: message.author.displayAvatarURL() })
- .setTimestamp()
- .setTitle(userDisplayName)
- .setDescription(formattedMessage.slice(0, 4000))
- .setThumbnail(message.author.displayAvatarURL({ dynamic: true }));
- if (imageAttachments) {
- chatEmbed.setImage(imageAttachments);
- }
- await targetChannel.send({ embeds: [chatEmbed] }).catch(() => {
- message.reply("❌ An error occurred while trying to send your message. Please try again later.");
- });
- })
- );
- });
- async function getUserBadge(userId) {
- const userBadges = [];
- if (userId === "299729731237052417") {
- return { name: "👑 CC Owner", icon: "👑" };
- }
- if (userId === "909515934400643112") {
- return { name: "🛠️ CC Developer", icon: "🛠️" };
- }
- const guilds = client.guilds.cache.values();
- for (const guild of guilds) {
- const member = await guild.members.fetch(userId).catch(() => null);
- if (member) {
- if (member.roles.cache.has("1202408787810459657")) {
- return { name: "🟦 CubeCloud Member", icon: "🟦" };
- } else if (member.roles.cache.has("1202408787877826593")) {
- return { name: "👨💻 Staff", icon: "👨💻" };
- } else if (member.roles.cache.has("1202408787764449350")) {
- return { name: "👥 CC Member", icon: "👥" };
- }
- }
- }
- return { name: "👤 CC Guest", icon: "👤" };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement