mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
213 lines
6.3 KiB
JavaScript
213 lines
6.3 KiB
JavaScript
const {
|
|
EmbedBuilder,
|
|
StringSelectMenuBuilder,
|
|
ActionRowBuilder,
|
|
} = require("discord.js");
|
|
const db = require("../../fonctions/database.js");
|
|
const embedColor = require("../../fonctions/embedColor.js");
|
|
|
|
module.exports = {
|
|
aliases: [],
|
|
description: "Change la couleur de vos embed.",
|
|
emote: "🔵",
|
|
utilisation: "",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🔵 Embed")
|
|
.setDescription(`Sélectionnez une couleur pour vos embeds`)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
const select = new StringSelectMenuBuilder()
|
|
.setCustomId("color")
|
|
.setPlaceholder("Sélectionnez une couleur")
|
|
.addOptions([
|
|
{
|
|
label: "🔴 Rouge",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "red",
|
|
},
|
|
{
|
|
label: "🟠 Orange",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "orange",
|
|
},
|
|
{
|
|
label: "🟡 Jaune",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "yellow",
|
|
},
|
|
{
|
|
label: "🟢 Vert",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "green",
|
|
},
|
|
{
|
|
label: "🔵 Bleu",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "blue",
|
|
},
|
|
{
|
|
label: "🟣 Violet",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "purple",
|
|
},
|
|
{
|
|
label: "🟤 Marron",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "brown",
|
|
},
|
|
{
|
|
label: "⚫ Noir",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "black",
|
|
},
|
|
{
|
|
label: "⚪ Blanc",
|
|
description: "Prix : 3 rep🔺",
|
|
value: "white",
|
|
},
|
|
{
|
|
label: "Aléatoire 🌈",
|
|
description: "Prix : 5 rep🔺",
|
|
value: "random",
|
|
},
|
|
]);
|
|
|
|
const row = new ActionRowBuilder().addComponents(select);
|
|
|
|
const embedMessage = await message.reply({
|
|
embeds: [embed],
|
|
components: [row],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
|
|
const filter = (interaction) => interaction.user.id === message.author.id;
|
|
const collector = embedMessage.createMessageComponentCollector({
|
|
filter,
|
|
time: 60000,
|
|
});
|
|
collector.on("collect", async (interaction) => {
|
|
if (interaction.isStringSelectMenu()) {
|
|
if (!client.user) return;
|
|
const value = interaction.values[0];
|
|
const user = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
|
[message.guild.id, message.author.id],
|
|
(err, row) => {
|
|
if (err) reject(err);
|
|
resolve(row);
|
|
},
|
|
);
|
|
});
|
|
const reputation = user.reputation;
|
|
|
|
if (value === "random") {
|
|
if (reputation < 5) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Erreur")
|
|
.setDescription(
|
|
"❌ Vous n'avez pas assez de réputations pour acheter cette couleur.",
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return interaction.reply({
|
|
embeds: [embed],
|
|
ephemeral: true,
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
|
|
db.run(
|
|
`UPDATE users SET reputation = reputation - 5, embed = 'random' WHERE guildId = ? AND userId = ?`,
|
|
[message.guild.id, message.author.id],
|
|
(err) => {
|
|
if (err) return console.error(err);
|
|
},
|
|
);
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🔵 Embed")
|
|
.setDescription(
|
|
"✅ Vous avez acheté la couleur aléatoire pour vos embeds.",
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
interaction.reply({
|
|
embeds: [embed],
|
|
ephemeral: true,
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
} else {
|
|
if (reputation < 3) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Erreur")
|
|
.setDescription(
|
|
"❌ Vous n'avez pas assez de réputations pour acheter cette couleur.",
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return interaction.reply({
|
|
embeds: [embed],
|
|
ephemeral: true,
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
|
|
db.run(
|
|
`UPDATE users SET reputation = reputation - 3, embed = ? WHERE guildId = ? AND userId = ?`,
|
|
[value, message.guild.id, message.author.id],
|
|
(err) => {
|
|
if (err) return console.error(err);
|
|
},
|
|
);
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🔵 Embed")
|
|
.setDescription(
|
|
`✅ Vous avez acheté la couleur ${value} pour vos embeds.`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
interaction.reply({
|
|
embeds: [embed],
|
|
ephemeral: true,
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
collector.on("end", async () => {
|
|
embedMessage.edit({ components: [] });
|
|
});
|
|
},
|
|
};
|