nyx/command/Config/premium.js

129 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-10-26 12:38:28 +02:00
const { EmbedBuilder } = require("discord.js");
2021-09-21 01:51:56 +02:00
module.exports = {
name: "premiumserver",
category: "Config",
description: "Add premium to a server",
Premium: true,
options: [
{
type: 5,
name: "choice",
description: "Whether add or remove premium server",
required: true,
},
],
run: async (client, interaction) => {
2021-09-21 01:51:56 +02:00
try {
const user = await client.data.getUser(interaction.user.id);
const guild = await client.data.getGuild(interaction.guild.id);
2023-04-06 14:23:31 +02:00
if (interaction.options.getBoolean("choice")) {
if (guild.Premium) {
return interaction.followUp({
content: "This server is already premium",
});
2021-09-21 01:51:56 +02:00
}
if (
(user.Tier == 1 && user.PremiumServers.length >= 5) ||
(user.Tier == 2 && user.PremiumServers.length >= 2) ||
(user.Tier == 3 && user.PremiumServers.length >= 0)
) {
interaction.followUp({
content:
"You have already reached the maximum amount of premium servers",
});
2021-09-21 01:51:56 +02:00
} else {
await client.data.setPremium(interaction.guild.id, "true");
await client.data.pushGuild(
interaction.user.id,
interaction.guild.id,
"push"
);
interaction.followUp({
embeds: [
2022-10-26 12:38:28 +02:00
new EmbedBuilder()
2021-09-21 01:51:56 +02:00
.setTitle("Success!")
.setDescription(
`Premium added to **${interaction.guild.name}**! \n`
)
2022-10-26 12:38:28 +02:00
.setFooter({ text: "Thank you for supporting Cath!" })
.setColor("Green")
2021-09-21 01:51:56 +02:00
.setTimestamp()
2023-04-06 14:23:31 +02:00
.setAuthor({
name: interaction.user.tag,
iconURL: interaction.user.displayAvatarURL({ dynamic: true }),
}),
2021-09-21 01:51:56 +02:00
],
});
client.channels.cache.get(client.config.ServerLog).send({
2021-09-21 01:51:56 +02:00
embeds: [
2022-10-26 12:38:28 +02:00
new EmbedBuilder()
2021-09-21 01:51:56 +02:00
.setTitle("New Premium Server")
2023-04-06 14:23:31 +02:00
.addFields({
name: "Server Info",
value: `**>Server Name**: \n${interaction.guild.name}
2021-09-21 01:51:56 +02:00
**>Server ID**: \n${interaction.guild.id}
2023-04-06 14:23:31 +02:00
**>Server Member Count**: \n${interaction.guild.memberCount}`,
})
2021-09-21 01:51:56 +02:00
.setTimestamp()
.setThumbnail(interaction.guild.iconURL({ dynamic: true }))
.setColor("Green"),
2021-09-21 01:51:56 +02:00
],
});
}
} else {
2023-04-06 14:23:31 +02:00
if (!guild.Premium) {
return interaction.followUp({
content: "This server isn't premium yet",
});
2021-09-21 01:51:56 +02:00
}
if (!user.PremiumServers.includes(interaction.guild.id)) {
2023-04-06 14:23:31 +02:00
return interaction.followUp({
content:
"You can't remove due to you aren't the person who made the server premium",
});
} else {
2021-09-21 01:51:56 +02:00
await client.data.setPremium(interaction.guild.id, "false");
await client.data.pushGuild(
interaction.user.id,
interaction.guild.id,
"splice"
);
interaction.followUp({
embeds: [
2022-10-26 12:38:28 +02:00
new EmbedBuilder()
2021-09-21 01:51:56 +02:00
.setTitle("Removed!")
.setDescription(
`Premium removed from **${interaction.guild.name}**! \n`
)
2023-02-03 23:28:45 +01:00
.setColor("Red")
2021-09-21 01:51:56 +02:00
.setTimestamp()
2023-04-06 14:23:31 +02:00
.setAuthor({
name: interaction.user.tag,
iconURL: interaction.user.displayAvatarURL({ dynamic: true }),
}),
2021-09-21 01:51:56 +02:00
],
});
client.channels.cache.get(client.config.ServerLog).send({
2021-09-21 01:51:56 +02:00
embeds: [
2022-10-26 12:38:28 +02:00
new EmbedBuilder()
2021-09-21 01:51:56 +02:00
.setTitle("Premium Server Removed")
2023-04-06 14:23:31 +02:00
.addFields({
name: "Server Info",
value: `**>Server Name**: \n${interaction.guild.name}
2021-09-21 01:51:56 +02:00
**>Server ID**: \n${interaction.guild.id}
2023-04-06 14:23:31 +02:00
**>Server Member Count**: \n${interaction.guild.memberCount}`,
})
2021-09-21 01:51:56 +02:00
.setTimestamp()
.setThumbnail(interaction.guild.iconURL({ dynamic: true }))
2023-02-03 23:28:45 +01:00
.setColor("Red"),
2021-09-21 01:51:56 +02:00
],
});
}
}
} catch (e) {
console.log(e);
interaction.followUp({ content: `**Error**: ${e.message}` });
2021-09-21 01:51:56 +02:00
}
},
};