From de8e7c0ef9a78c24a4b3bd9749cd6659153a2c06 Mon Sep 17 00:00:00 2001 From: UltraLion <49597041+UltraLionfr@users.noreply.github.com> Date: Sat, 5 Nov 2022 23:05:36 +0100 Subject: [PATCH] Create threadCreate.js --- events/threadCreate.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 events/threadCreate.js diff --git a/events/threadCreate.js b/events/threadCreate.js new file mode 100644 index 0000000..6049b4b --- /dev/null +++ b/events/threadCreate.js @@ -0,0 +1,36 @@ +const { Message, ActionRowBuilder, ButtonBuilder, ChannelType, ButtonStyle, EmbedBuilder } = require("discord.js"); +const client = require("../index"); +const config = require("../config.json"); + +client.on('threadCreate', async (thread) => { + if (thread.type == ChannelType.GuildPublicThread) { + for (let i = 0; i < config.forumPostChannelId.length; i++) { + if (thread.parentId == config.forumPostChannelId[i]) { + const row = new ActionRowBuilder() + if (config.forumPostButtons.hasOwnProperty(thread.parentId)) { + let check = config.forumPostButtons[thread.parentId] + for (let j = 0; j < check.length; j++) { + row.addComponents( + new ButtonBuilder() + .setStyle(ButtonStyle.Link) + .setLabel(config.forumPostButtons[thread.parentId][j].label) + .setURL(config.forumPostButtons[thread.parentId][j].url) + ) + } + } + const button = new ButtonBuilder() // first button for all post (for example the button can redirect to the server rules) + .setLabel("💾• github") + .setURL("https://github.com/UltraLionfr") + .setStyle(ButtonStyle.Link) + row.addComponents(button) + const embed = new EmbedBuilder() + .setTitle(config.forumPostTitle[i]) + .setDescription(config.forumPostMessage[i]) + .setTimestamp() + .setColor("#B9E0A2") // embed color for all post + .setFooter({ text: "© made by UltaLion ❤️", iconURL: 'https://avatars.githubusercontent.com/u/49597041?v=4'}) + await thread.send({ embeds: [embed], components: [row] }) + } + } + } +})