8.4-DEV-2
Added Buttons to WelcomeMessage Added Components v2 Support for Welcome Message Added improved logging system
This commit is contained in:
1 parent
a05d65099b
commit
7383bd2c48
16 files changed
+459
-290
No files matched your search
+137
-42
@@ -1,56 +1,151 @@
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const {
|
||||
EmbedBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
MessageFlags,
|
||||
ContainerBuilder,
|
||||
TextDisplayBuilder,
|
||||
SectionBuilder,
|
||||
ThumbnailBuilder,
|
||||
AttachmentBuilder
|
||||
} = require("discord.js");
|
||||
const fs = require("fs");
|
||||
const Event = require("../Structures/Event.js");
|
||||
const yaml = require("js-yaml");
|
||||
const Event = require("../Structures/Event.js");
|
||||
|
||||
const supportbot = yaml.load(
|
||||
fs.readFileSync("./Configs/supportbot.yml", "utf8")
|
||||
);
|
||||
|
||||
const cmdconfig = yaml.load(
|
||||
fs.readFileSync("./Configs/commands.yml", "utf8")
|
||||
);
|
||||
|
||||
const msgconfig = yaml.load(
|
||||
fs.readFileSync("./Configs/messages.yml", "utf8")
|
||||
);
|
||||
|
||||
module.exports = new Event("guildMemberAdd", async (client, member, interaction, guild) => {
|
||||
function getWelcomeThumbnail(client, member, iconCfg) {
|
||||
switch ((iconCfg?.Mode || "").toUpperCase()) {
|
||||
case "USER":
|
||||
return member.user.displayAvatarURL();
|
||||
case "BOT":
|
||||
return client.user.displayAvatarURL();
|
||||
case "CUSTOM":
|
||||
return iconCfg.CustomURL;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (supportbot.Welcome.Enabled) {
|
||||
const WelcomeChannel = member.guild.channels.cache.get(supportbot.Welcome.Channel) ||
|
||||
member.guild.channels.cache.find(channel => channel.name === supportbot.Welcome.Channel);
|
||||
function buildModernComponents(client, member) {
|
||||
const container = new ContainerBuilder().setAccentColor(
|
||||
parseInt(msgconfig.Welcome.Modern.Colour.replace("#", ""), 16)
|
||||
);
|
||||
|
||||
const WelcomeEmbed = new Discord.EmbedBuilder()
|
||||
.setColor(msgconfig.Welcome.Embed.Colour)
|
||||
.setTitle(msgconfig.Welcome.Embed.Title)
|
||||
.setDescription(msgconfig.Welcome.Embed.Message.replace(/%joined_user%/g, member.user))
|
||||
.setTimestamp();
|
||||
|
||||
if (msgconfig.Welcome.Embed.Thumbnail === "BOT") {
|
||||
WelcomeEmbed.setThumbnail(client.user.displayAvatarURL())
|
||||
} else if (msgconfig.Welcome.Embed.Thumbnail === "USER") {
|
||||
WelcomeEmbed.setThumbnail(member.user.displayAvatarURL())
|
||||
}
|
||||
|
||||
if (msgconfig.Welcome.Embed.ImageEnabled) {
|
||||
WelcomeEmbed.setImage(msgconfig.Welcome.Embed.ImageURL)
|
||||
}
|
||||
|
||||
if (WelcomeChannel) {
|
||||
WelcomeChannel.send({ embeds: [WelcomeEmbed] });
|
||||
}
|
||||
|
||||
if (supportbot.Roles.AutoRole.Enabled) {
|
||||
const role = member.guild.roles.cache.get(supportbot.Roles.AutoRole.Role) ||
|
||||
member.guild.roles.cache.find(role => role.name === supportbot.Roles.AutoRole.Role);
|
||||
if (role) {
|
||||
member.roles.add(role);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\u001b[32m`, `[+]`, `\u001b[33m`, `${member.user.username} joined the server!`);
|
||||
const section = new SectionBuilder().addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
msgconfig.Welcome.Modern.Title.replace(/%joined_user%/g, member.user)
|
||||
),
|
||||
new TextDisplayBuilder().setContent(
|
||||
msgconfig.Welcome.Modern.Body.replace(/%joined_user%/g, member.user)
|
||||
)
|
||||
);
|
||||
|
||||
const thumbUrl = getWelcomeThumbnail(client, member, msgconfig.Welcome.Modern.Icon);
|
||||
if (thumbUrl) {
|
||||
section.setThumbnailAccessory(
|
||||
new ThumbnailBuilder()
|
||||
.setURL(thumbUrl)
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
container.addSectionComponents(section);
|
||||
|
||||
if (msgconfig.Welcome.Modern.Image?.Enabled && msgconfig.Welcome.Modern.Image.URL) {
|
||||
container.addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
``
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (Array.isArray(msgconfig.Welcome.Modern.Buttons)) {
|
||||
const row = new ActionRowBuilder();
|
||||
msgconfig.Welcome.Modern.Buttons.slice(0, 5).forEach(b => {
|
||||
const btn = new ButtonBuilder()
|
||||
.setLabel(b.label)
|
||||
.setStyle(ButtonStyle[b.style])
|
||||
.setEmoji(b.emoji || null);
|
||||
if (b.style === "Link") btn.setURL(b.url);
|
||||
else if (b.customId) btn.setCustomId(b.customId);
|
||||
row.addComponents(btn);
|
||||
});
|
||||
|
||||
container.addActionRowComponents(row);
|
||||
}
|
||||
|
||||
return [container];
|
||||
}
|
||||
|
||||
module.exports = new Event("guildMemberAdd", async (client, member) => {
|
||||
if (!supportbot.Welcome.Enabled) return;
|
||||
|
||||
const WelcomeChannel =
|
||||
member.guild.channels.cache.get(supportbot.Welcome.Channel) ||
|
||||
member.guild.channels.cache.find(c => c.name === supportbot.Welcome.Channel);
|
||||
if (!WelcomeChannel) return;
|
||||
|
||||
const style = (msgconfig.Welcome.LayoutStyle || "classic").toLowerCase();
|
||||
|
||||
if (style === "classic") {
|
||||
const WelcomeEmbed = new EmbedBuilder()
|
||||
.setColor(msgconfig.Welcome.Embed.Colour)
|
||||
.setTitle(msgconfig.Welcome.Embed.Title || null)
|
||||
.setDescription(
|
||||
msgconfig.Welcome.Embed.Message.replace(/%joined_user%/g, member.user)
|
||||
)
|
||||
.setTimestamp();
|
||||
|
||||
const thumb = getWelcomeThumbnail(client, member, msgconfig.Welcome.Embed.Icon);
|
||||
if (thumb) WelcomeEmbed.setThumbnail(thumb);
|
||||
|
||||
if (msgconfig.Welcome.Embed.Image?.Enabled && msgconfig.Welcome.Embed.Image.URL) {
|
||||
WelcomeEmbed.setImage(msgconfig.Welcome.Embed.Image.URL);
|
||||
}
|
||||
|
||||
const components = [];
|
||||
if (
|
||||
msgconfig.Welcome.Embed.Buttons?.Enabled &&
|
||||
Array.isArray(msgconfig.Welcome.Embed.Buttons.List)
|
||||
) {
|
||||
const row = new ActionRowBuilder();
|
||||
msgconfig.Welcome.Embed.Buttons.List.slice(0, 5).forEach(b => {
|
||||
const btn = new ButtonBuilder()
|
||||
.setLabel(b.label)
|
||||
.setStyle(ButtonStyle[b.style])
|
||||
.setEmoji(b.emoji || null);
|
||||
if (b.style === "Link") btn.setURL(b.url);
|
||||
else if (b.customId) btn.setCustomId(b.customId);
|
||||
row.addComponents(btn);
|
||||
});
|
||||
components.push(row);
|
||||
}
|
||||
|
||||
await WelcomeChannel.send({ embeds: [WelcomeEmbed], components });
|
||||
} else if (style === "modern") {
|
||||
const components = buildModernComponents(client, member);
|
||||
if (components.length > 0) {
|
||||
await WelcomeChannel.send({
|
||||
components,
|
||||
flags: MessageFlags.IsComponentsV2
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (supportbot.Roles.AutoRole.Enabled) {
|
||||
const role =
|
||||
member.guild.roles.cache.get(supportbot.Roles.AutoRole.Role) ||
|
||||
member.guild.roles.cache.find(r => r.name === supportbot.Roles.AutoRole.Role);
|
||||
if (role) await member.roles.add(role);
|
||||
}
|
||||
|
||||
console.log("\u001b[32m", "[+]", "\u001b[33m", `${member.user.username} joined the server!`);
|
||||
|
||||
});
|
||||
+32
-42
@@ -1,50 +1,40 @@
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const { EmbedBuilder } = require("discord.js");
|
||||
const fs = require("fs");
|
||||
const Event = require("../Structures/Event.js");
|
||||
const yaml = require("js-yaml");
|
||||
const Event = require("../Structures/Event.js");
|
||||
|
||||
const supportbot = yaml.load(
|
||||
fs.readFileSync("./Configs/supportbot.yml", "utf8")
|
||||
);
|
||||
|
||||
const cmdconfig = yaml.load(
|
||||
fs.readFileSync("./Configs/commands.yml", "utf8")
|
||||
);
|
||||
|
||||
const msgconfig = yaml.load(
|
||||
fs.readFileSync("./Configs/messages.yml", "utf8")
|
||||
);
|
||||
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));
|
||||
const msgconfig = yaml.load(fs.readFileSync("./Configs/messages.yml", "utf8"));
|
||||
|
||||
module.exports = new Event("guildMemberRemove", async (client, member, interaction, guild) => {
|
||||
module.exports = new Event("guildMemberRemove", async (client, member) => {
|
||||
|
||||
if (supportbot.Leave.Enabled) {
|
||||
const LeaveChannel = member.guild.channels.cache.get(supportbot.Leave.Channel) ||
|
||||
member.guild.channels.cache.find(channel => channel.name === supportbot.Leave.Channel);
|
||||
if (!supportbot.Leave || !supportbot.Leave.Enabled) return;
|
||||
|
||||
const LeaveEmbed = new Discord.EmbedBuilder()
|
||||
.setColor(msgconfig.Leave.Embed.Colour)
|
||||
.setTitle(msgconfig.Leave.Embed.Title)
|
||||
.setDescription(msgconfig.Leave.Embed.Message.replace(/%left_user%/g, member.user))
|
||||
.setTimestamp();
|
||||
|
||||
if (msgconfig.Leave.Embed.Thumbnail === "BOT") {
|
||||
LeaveEmbed.setThumbnail(client.user.displayAvatarURL());
|
||||
} else if (msgconfig.Leave.Embed.Thumbnail === "USER") {
|
||||
LeaveEmbed.setThumbnail(member.user.displayAvatarURL());
|
||||
}
|
||||
|
||||
if (msgconfig.Leave.Embed.ImageEnabled) {
|
||||
LeaveEmbed.setImage(msgconfig.Leave.Embed.ImageURL);
|
||||
}
|
||||
|
||||
if (LeaveChannel) {
|
||||
LeaveChannel.send({
|
||||
embeds: [LeaveEmbed]
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`\u001b[31m`, `[-]`, `\u001b[33m`, `${member.user.username} left the server!`);
|
||||
const leaveChannel =
|
||||
member.guild.channels.cache.get(supportbot.Leave.Channel) ||
|
||||
member.guild.channels.cache.find(c => c.name === supportbot.Leave.Channel);
|
||||
|
||||
if (!leaveChannel) return;
|
||||
|
||||
const leaveEmbed = new EmbedBuilder()
|
||||
.setColor(msgconfig.Leave.Embed.Colour)
|
||||
.setTitle(msgconfig.Leave.Embed.Title)
|
||||
.setDescription(
|
||||
msgconfig.Leave.Embed.Message.replace(/%left_user%/g, member.user.toString())
|
||||
)
|
||||
.setTimestamp();
|
||||
|
||||
if (msgconfig.Leave.Embed.Thumbnail === "BOT") {
|
||||
leaveEmbed.setThumbnail(client.user.displayAvatarURL());
|
||||
} else if (msgconfig.Leave.Embed.Thumbnail === "USER") {
|
||||
leaveEmbed.setThumbnail(member.user.displayAvatarURL());
|
||||
}
|
||||
|
||||
});
|
||||
if (msgconfig.Leave.Embed.ImageEnabled) {
|
||||
leaveEmbed.setImage(msgconfig.Leave.Embed.ImageURL);
|
||||
}
|
||||
|
||||
await leaveChannel.send({ embeds: [leaveEmbed] });
|
||||
|
||||
console.log(`[-] ${member.user.tag} left the server`);
|
||||
});
|
||||
+16
-15
@@ -25,7 +25,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
if (!command)
|
||||
return interaction.reply({
|
||||
embeds: [NotValid],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
|
||||
const permission = interaction.member.permissions.has(command.permissions);
|
||||
@@ -39,7 +39,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
if (!permission)
|
||||
return interaction.reply({
|
||||
embeds: [ValidPerms],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -66,7 +66,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
console.error("Error executing command:", error);
|
||||
await interaction.reply({
|
||||
content: "An error occurred while executing the command.",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
if (!ticketChannel) {
|
||||
return interaction.reply({
|
||||
content: "Ticket channel not found.",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
try {
|
||||
@@ -107,16 +107,17 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
.setColor(supportbot.Embed.Colours.Success);
|
||||
return interaction.reply({
|
||||
embeds: [renamedsuccess],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error renaming the ticket:", error);
|
||||
return interaction.reply({
|
||||
content: "There was an error renaming the ticket.",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (interaction.isStringSelectMenu()) {
|
||||
if (interaction.customId === "ticketcontrolpanel") {
|
||||
const selectedOption = interaction.values[0];
|
||||
@@ -151,7 +152,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
if (!VCcategory) {
|
||||
return interaction.reply({
|
||||
content: "⚠️ The Support VC category does not exist!",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -343,7 +344,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
.setColor(supportbot.Embed.Colours.Success);
|
||||
await interaction.reply({
|
||||
embeds: [successEmbed],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
} else {
|
||||
const errorEmbed = new Discord.EmbedBuilder()
|
||||
@@ -351,7 +352,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
.setColor(supportbot.Embed.Colours.Error);
|
||||
await interaction.reply({
|
||||
embeds: [errorEmbed],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -361,7 +362,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
.setColor(supportbot.Embed.Colours.Error);
|
||||
await interaction.reply({
|
||||
embeds: [errorEmbed],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -370,7 +371,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
.setColor(supportbot.Embed.Colours.Warn);
|
||||
await interaction.reply({
|
||||
embeds: [errorEmbed],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -462,7 +463,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
console.error("Error executing the ticket command:", error);
|
||||
await interaction.reply({
|
||||
content: "An error occurred while creating the ticket.",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -500,7 +501,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
if (!ticketChannel) {
|
||||
return interaction.reply({
|
||||
content: "Ticket channel not found.",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -675,7 +676,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -725,7 +726,7 @@ module.exports = new Event("interactionCreate", async (client, interaction) => {
|
||||
console.error("Failed to update profile data: ", error);
|
||||
await interaction.reply({
|
||||
content: "There was an error while updating your profile. Please try again later.",
|
||||
ephemeral: true,
|
||||
flags: Discord.MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+11
-18
@@ -3,41 +3,34 @@ const fs = require("fs");
|
||||
const yaml = require("js-yaml");
|
||||
const Event = require("../Structures/Event.js");
|
||||
|
||||
// Load the configuration files
|
||||
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));
|
||||
const msgconfig = yaml.load(fs.readFileSync("./Configs/messages.yml", "utf8"));
|
||||
|
||||
module.exports = new Event("messageDelete", async (client, message) => {
|
||||
if (!message.guild) return;
|
||||
|
||||
// Check if the message is from a guild and not from a bot
|
||||
if (!message.guild || message.author.bot) return;
|
||||
const author = message.author || (message.partial ? await message.fetch().then(m => m.author).catch(() => null) : null);
|
||||
if (!author || author.bot) return;
|
||||
|
||||
const content = message.content || (message.attachments.size > 0 ? "Contains attachment(s)" : "*No content*");
|
||||
|
||||
// Get the delete log channel either by ID or by name
|
||||
const deleteLogChannel = message.guild.channels.cache.get(supportbot.MessageDelete.Channel) ||
|
||||
message.guild.channels.cache.find(channel => channel.name === supportbot.MessageDelete.Channel);
|
||||
message.guild.channels.cache.find(c => c.name === supportbot.MessageDelete.Channel);
|
||||
|
||||
// Create the embed for the deleted message
|
||||
const deletedMessageEmbed = new EmbedBuilder()
|
||||
.setColor(supportbot.MessageDelete.Colour)
|
||||
.setTitle("Message Deleted")
|
||||
.setDescription(`> **Channel:** <#${message.channel.id}>\n> **Message ID** [${message.id}](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id})\n> **Message author:** ${message.author.tag} (${message.author.id})\n> **Message Crated:** <t:${Math.floor(message.createdTimestamp / 1000)}:F>`)
|
||||
.addFields(
|
||||
{ name: 'Message', value: message.content || '*No content*', inline: false }
|
||||
)
|
||||
.setThumbnail(message.author.displayAvatarURL())
|
||||
.setDescription(`> **Channel:** <#${message.channel.id}>\n> **Message ID:** ${message.id}\n> **Message author:** ${author.tag} (${author.id})\n> **Message Created:** <t:${Math.floor(message.createdTimestamp / 1000)}:F>`)
|
||||
.addFields({ name: "Deleted Content", value: content, inline: false })
|
||||
.setThumbnail(author.displayAvatarURL())
|
||||
.setTimestamp();
|
||||
|
||||
// If the message contains an attachment, add it to the embed
|
||||
if (message.attachments.size > 0) {
|
||||
const attachment = message.attachments.first();
|
||||
deletedMessageEmbed.addFields({ name: 'Attachment', value: `[${attachment.name}](${attachment.proxyURL})` });
|
||||
deletedMessageEmbed.addFields({ name: "Attachment", value: `[${attachment.name}](${attachment.proxyURL})` });
|
||||
}
|
||||
|
||||
// Send the embed to the delete log channel if the channel is found
|
||||
if (deleteLogChannel) {
|
||||
deleteLogChannel.send({
|
||||
embeds: [deletedMessageEmbed]
|
||||
});
|
||||
deleteLogChannel.send({ embeds: [deletedMessageEmbed] });
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -125,4 +125,4 @@ module.exports = new Event("clientReady", async (client) => {
|
||||
setActivity(client, supportbot?.Activity?.Type, supportbot?.Activity?.Status);
|
||||
await logStartup(client);
|
||||
await checkConfigs(client);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user