Files
SupportBot/Commands/embed.js
T

120 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-10-24 22:41:46 +01:00
// SupportBot | Emerald Services
// Embed Command
const fs = require("fs");
const Discord = require("discord.js");
const yaml = require("js-yaml");
2022-08-12 01:35:36 +01:00
2021-10-27 19:30:10 -05:00
const supportbot = yaml.load(
fs.readFileSync("./Configs/supportbot.yml", "utf8")
);
2022-08-12 01:35:36 +01:00
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,
},
{
name: "fieldtitle",
description: "Add an additional Embed Field",
2022-07-22 13:19:05 +01:00
type: Discord.ApplicationCommandOptionType.String,
2022-02-27 04:30:15 +00:00
required: false,
},
{
name: "fieldcontent",
description: "Add an additional Embed Field",
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-08-11 19:19:29 +01:00
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,
},
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-07-23 07:50:12 +01:00
let disableCommand = true;
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
if (!SupportStaff || !Admin)
2021-11-21 18:42:18 -06:00
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
const NoPerms = new Discord.EmbedBuilder()
2021-10-24 22:41:46 +01:00
.setTitle("Invalid Permissions!")
.setDescription(
2022-08-12 01:35:36 +01:00
`${msgconfig.Error.IncorrectPerms}\n\nRole Required: \`${supportbot.Roles.StaffMember.Staff}\` or \`${supportbot.Roles.StaffMember.Admin}\``
2021-10-24 22:41:46 +01:00
)
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
) {
2021-10-25 00:02:23 -05:00
const EmbedTitle = interaction.options.getString("title");
const EmbedSubject = interaction.options.getString("message");
2022-07-22 13:19:05 +01:00
const GeneralColour = interaction.options.getString("color");
2022-02-27 04:30:15 +00:00
const EmbedThumbnail = interaction.options.getString("thumbnail");
const EmbedImage = interaction.options.getString("image");
const EmbedFieldContent = interaction.options.getString("fieldcontent");
const EmbedFieldTitle = interaction.options.getString("fieldtitle");
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)
2022-06-22 20:59:45 +02:00
.setImage(EmbedImage)
if (EmbedFieldTitle && EmbedFieldContent) { EmbedMsg.addField(EmbedFieldTitle, EmbedFieldContent) };
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
}
},
});