const { MessageEmbed } = require('discord.js'); module.exports = { name: "id-set", debug: false, description: "Set a value on your wallet ID", usage: "[firstname/lastname/dob] [value]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, SlashCommand: { options: [ { name: "change", description: "What you'd like to change on your ID", value: "change", type: 3, required: true, choices: [ { name: "firstname", value: "firstname" }, { name: "lastname", value: "lastname" }, { name: "date-of-birth", value: "dob" }, ], }, { name: "value", description: "New value of what you'd like to change", value: "value", type: 3, required: true, }, ], /** * * @param {require("../structures/QuarksBot")} client * @param {import("discord.js").MessageCreate} message * @param {string[]} args * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }) => { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } const query = {"inventory.userID":interaction.member.user.id, "inventory.items.type":"wallet"}; let update, updateAction; if (args[0].value == "firstname") { update = {$set: {"inventory.items.$.ID.firstname": args[1].value}}; updateAction = "firstname"; } else if (args[0].value == "lastname") { update = {$set: {"inventory.items.$.ID.lastname": args[1].value}}; updateAction = "lastname"; } else if (args[0].value == "dob") { const isDate = (date) => { return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date)); } if (!isDate(args[1].value)) { let embed = new MessageEmbed() .setTitle("Invalid Date of Birth") .setColor("RED"); return interaction.send({ embeds: [embed] }); } update = {$set: {"inventory.items.$.ID.dob": args[1].value}}; updateAction = "date of birth"; } client.dbo.collection("inventories").updateOne(query, update, function (err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); let successEmbed = new MessageEmbed() .setTitle('Success') .setDescription(`Successfully set ${updateAction}\nUse \`/inventory wallet\` to view your updated ID`) .setColor('GREEN'); return interaction.send({ embeds: [successEmbed] }); }, }, }