Files
SupportBot/Commands/embed.js
T

167 lines
5.5 KiB
JavaScript
Raw Normal View History

2024-06-12 12:54:31 +01:00
// File path: ./commands/embed.js
2021-10-24 22:41:46 +01:00
const fs = require("fs");
const Discord = require("discord.js");
const yaml = require("js-yaml");
2022-08-12 01:35:36 +01:00
2024-06-12 12:54:31 +01:00
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"));
2021-10-24 22:41:46 +01:00
const Command = require("../Structures/Command.js");
module.exports = new Command({
2022-07-23 07:50:12 +01:00
name: cmdconfig.Embed.Command,
description: cmdconfig.Embed.Description,
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandType.ChatInput,
options: [
2021-10-24 22:41:46 +01:00
{
2021-10-25 00:02:23 -05:00
name: "title",
description: "Embed Title",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2021-12-29 10:20:29 -06:00
required: true,
2021-10-25 00:02:23 -05:00
},
2021-10-24 22:41:46 +01:00
{
name: "message",
description: "Embed Message",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2021-12-29 10:20:29 -06:00
required: true,
2021-10-24 22:41:46 +01:00
},
2022-02-27 04:30:15 +00:00
{
name: "color",
description: "Embed HEX Color",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2022-02-27 04:30:15 +00:00
required: false,
},
{
2024-06-12 12:54:31 +01:00
name: "fields",
description: "Embed Fields (title|content;title|content;...)",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2022-02-27 04:30:15 +00:00
required: false,
},
{
name: "thumbnail",
description: "Embed Thumbnail URL",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2022-02-27 04:30:15 +00:00
required: false,
},
{
name: "image",
description: "Embed Image URL",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2022-02-27 04:30:15 +00:00
required: false,
},
2024-06-12 12:54:31 +01:00
{
name: "footer",
description: "Embed Footer Text",
type: Discord.ApplicationCommandOptionType.String,
required: false,
},
{
name: "footericon",
description: "Embed Footer Icon URL",
type: Discord.ApplicationCommandOptionType.String,
required: false,
},
{
name: "author",
description: "Embed Author Name",
type: Discord.ApplicationCommandOptionType.String,
required: false,
},
{
name: "authoricon",
description: "Embed Author Icon URL",
type: Discord.ApplicationCommandOptionType.String,
required: false,
},
{
name: "authorurl",
description: "Embed Author URL",
type: Discord.ApplicationCommandOptionType.String,
required: false,
},
{
name: "timestamp",
description: "Include Timestamp",
type: Discord.ApplicationCommandOptionType.Boolean,
required: false,
},
{
name: "inline",
description: "Make Fields Inline",
type: Discord.ApplicationCommandOptionType.Boolean,
required: false,
}
2021-10-24 22:41:46 +01:00
],
2022-07-23 07:50:12 +01:00
permissions: cmdconfig.Embed.Permission,
2021-10-24 22:41:46 +01:00
async run(interaction) {
2022-01-30 00:07:04 -06:00
const { getRole } = interaction.client;
2022-08-12 01:35:36 +01:00
let SupportStaff = await getRole(supportbot.Roles.StaffMember.Staff, interaction.guild);
let Admin = await getRole(supportbot.Roles.StaffMember.Admin, interaction.guild);
2021-10-24 22:41:46 +01:00
2024-06-12 12:54:31 +01:00
if (!SupportStaff || !Admin) {
return interaction.reply("Some roles seem to be missing!\nPlease check for errors when starting the bot.");
}
2022-08-12 01:35:36 +01:00
2024-06-12 12:54:31 +01:00
const NoPerms = new Discord.EmbedBuilder()
2021-10-24 22:41:46 +01:00
.setTitle("Invalid Permissions!")
2024-06-12 12:54:31 +01:00
.setDescription(`${msgconfig.Error.IncorrectPerms}\n\nRole Required: \`${supportbot.Roles.StaffMember.Staff}\` or \`${supportbot.Roles.StaffMember.Admin}\``)
2022-08-12 01:35:36 +01:00
.setColor(supportbot.Embed.Colours.Warn);
2021-10-24 22:41:46 +01:00
if (
interaction.member.roles.cache.has(SupportStaff.id) ||
interaction.member.roles.cache.has(Admin.id)
2021-10-24 22:41:46 +01:00
) {
2024-06-12 12:54:31 +01:00
const EmbedTitle = interaction.options.getString("title").replace(/\\n/g, '\n');
const EmbedSubject = interaction.options.getString("message").replace(/\\n/g, '\n');
const GeneralColour = interaction.options.getString("color") || supportbot.Embed.Colours.Default;
2022-02-27 04:30:15 +00:00
const EmbedThumbnail = interaction.options.getString("thumbnail");
const EmbedImage = interaction.options.getString("image");
2024-06-12 12:54:31 +01:00
const EmbedFields = interaction.options.getString("fields");
const EmbedFooter = interaction.options.getString("footer")?.replace(/\\n/g, '\n');
const EmbedFooterIcon = interaction.options.getString("footericon");
const EmbedAuthor = interaction.options.getString("author")?.replace(/\\n/g, '\n');
const EmbedAuthorIcon = interaction.options.getString("authoricon");
const EmbedAuthorURL = interaction.options.getString("authorurl");
const EmbedTimestamp = interaction.options.getBoolean("timestamp");
const InlineFields = interaction.options.getBoolean("inline");
2021-10-24 22:41:46 +01:00
2022-07-22 13:19:05 +01:00
const EmbedMsg = new Discord.EmbedBuilder()
2021-10-25 00:02:23 -05:00
.setTitle(EmbedTitle)
2022-02-27 04:30:15 +00:00
.setDescription(EmbedSubject)
2022-07-22 13:19:05 +01:00
.setColor(GeneralColour)
2022-02-27 04:30:15 +00:00
.setThumbnail(EmbedThumbnail)
2024-06-12 12:54:31 +01:00
.setImage(EmbedImage);
if (EmbedFields) {
const fieldsArray = EmbedFields.split(';');
fieldsArray.forEach(field => {
const [title, value] = field.split('|');
if (title && value) {
EmbedMsg.addFields({ name: title.replace(/\\n/g, '\n'), value: value.replace(/\\n/g, '\n'), inline: InlineFields || false });
}
});
}
if (EmbedFooter) {
EmbedMsg.setFooter({ text: EmbedFooter, iconURL: EmbedFooterIcon });
}
if (EmbedAuthor) {
EmbedMsg.setAuthor({ name: EmbedAuthor, iconURL: EmbedAuthorIcon, url: EmbedAuthorURL });
}
if (EmbedTimestamp) {
EmbedMsg.setTimestamp();
}
2021-10-24 22:41:46 +01:00
2021-10-25 00:02:23 -05:00
interaction.reply({
embeds: [EmbedMsg],
});
2021-10-24 22:41:46 +01:00
} else {
2021-10-25 00:02:23 -05:00
return interaction.reply({ embeds: [NoPerms] });
2021-10-24 22:41:46 +01:00
}
},
});