我在点击“打开工单”时遇到问题

问题描述 投票:0回答:0
throw er; // Unhandled 'error' event
^

CombinedPropertyError: Received one or more errors
    at ObjectValidator.handleIgnoreStrategy (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1252:70)
    at ObjectValidator.handleStrategy (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1105:47)
    at ObjectValidator.handle (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1205:17)
    at ObjectValidator.parse (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:201:88)
    at /root/Ticket-Bot/node_modules/@discordjs/builders/dist/index.js:918:163
    at Array.map (<anonymous>)
    at StringSelectMenuBuilder.addOptions (/root/Ticket-Bot/node_modules/@discordjs/builders/dist/index.js:918:34)
    at StringSelectMenuBuilder.addOptions (/root/Ticket-Bot/node_modules/discord.js/src/structures/StringSelectMenuBuilder.js:48:18)
    at Object.execute (/root/Ticket-Bot/events/interactionCreate.js:321:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:394:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
  errors: [
    [
      'label',
      ValidationError: Expected a string primitive
          at StringValidator.handle (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1705:70)
          at StringValidator.run (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:187:23)
          at runPredicate (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1215:32)
          at ObjectValidator.handleIgnoreStrategy (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1225:9)
          at ObjectValidator.handleStrategy (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1105:47)
          at ObjectValidator.handle (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1205:17)
          at ObjectValidator.parse (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:201:88)
          at /root/Ticket-Bot/node_modules/@discordjs/builders/dist/index.js:918:163
          at Array.map (<anonymous>)
          at StringSelectMenuBuilder.addOptions (/root/Ticket-Bot/node_modules/@discordjs/builders/dist/index.js:918:34) {
        validator: 's.string',
        given: undefined
      }
    ],
    [
      'value',
      ValidationError: Expected a string primitive
          at StringValidator.handle (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1705:70)
          at StringValidator.run (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:187:23)
          at runPredicate (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1215:32)
          at ObjectValidator.handleIgnoreStrategy (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1225:9)
          at ObjectValidator.handleStrategy (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1105:47)
          at ObjectValidator.handle (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:1205:17)
          at ObjectValidator.parse (/root/Ticket-Bot/node_modules/@sapphire/shapeshift/dist/index.js:201:88)
          at /root/Ticket-Bot/node_modules/@discordjs/builders/dist/index.js:918:163
          at Array.map (<anonymous>)
          at StringSelectMenuBuilder.addOptions (/root/Ticket-Bot/node_modules/@discordjs/builders/dist/index.js:918:34) {
        validator: 's.string',
        given: undefined
      }
    ]
  ]
}

Node.js v18.15.0

我试图修复它但我不确定。请帮助我。

这是我的互动创建:

const { PermissionFlagsBits } = require("discord.js");
const Discord = require("discord.js");

/*
Copyright 2023 Sayrix (github.com/Sayrix)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

module.exports = {
    name: "interactionCreate",
    once: false,
    async execute(interaction, client) {
        async function createTicket(ticketType, reasons) {
            await interaction
                .deferReply({ ephemeral: true })
                .catch((e) => console.log(e));

            let reason = [];
            let allReasons;
            if ((typeof reasons) === "object") {
                reasons.forEach(async r => {
                    reason.push(r.value);
                });
    
                allReasons = reason.map((r, i) => `Question ${i+1}: ${r}`).join(", ");
            };
            let ticketName = new String();

            if (ticketType.ticketNameOption) {
                ticketName = ticketType.ticketNameOption
                    .replace("USERNAME", interaction.user.username)
                    .replace("USERID", interaction.user.id)
                    .replace("TICKETCOUNT", (await client.db.get("temp.ticketCount")) || 0);
            } else {
                ticketName = client.config.ticketNameOption
                    .replace("USERNAME", interaction.user.username)
                    .replace("USERID", interaction.user.id)
                    .replace("TICKETCOUNT", (await client.db.get("temp.ticketCount")) || 0);
            }

            client.guilds.cache
                .get(client.config.guildId)
                .channels.create({
                    name: ticketName,
                    parent: ticketType.categoryId,
                    permissionOverwrites: [
                        {
                            id: interaction.guild.roles.everyone,
                            deny: [PermissionFlagsBits.ViewChannel],
                        },
                    ],
                })
                .then(async (channel) => {
                    client.log(
                        "ticketCreate",
                        {
                            user: {
                                tag: interaction.user.tag,
                                id: interaction.user.id,
                                avatarURL: interaction.user.displayAvatarURL(),
                            },
                            reason: allReasons,
                            ticketChannelId: channel.id,
                        },
                        client
                    );

                    await client.db.add("temp.ticketCount", 1);
                    const ticketId = await client.db.get("temp.ticketCount");
                    await client.db.set(`tickets_${channel.id}`, {
                        id: ticketId - 1,
                        category: ticketType,
                        reason: allReasons,
                        creator: interaction.user.id,
                        invited: [],
                        createdAt: Date.now(),
                        claimed: false,
                        claimedBy: null,
                        claimedAt: null,
                        closed: false,
                        closedBy: null,
                        closedAt: null,
                    });

                    channel.permissionOverwrites
                        .edit(interaction.user, {
                            SendMessages: true,
                            AddReactions: true,
                            ReadMessageHistory: true,
                            AttachFiles: true,
                            ViewChannel: true,
                        })
                        .catch((e) => console.log(e));

                    if (client.config.rolesWhoHaveAccessToTheTickets.length > 0) {
                        client.config.rolesWhoHaveAccessToTheTickets.forEach(
                            async (role) => {
                                channel.permissionOverwrites
                                    .edit(role, {
                                        SendMessages: true,
                                        AddReactions: true,
                                        ReadMessageHistory: true,
                                        AttachFiles: true,
                                        ViewChannel: true,
                                    })
                                    .catch((e) => console.log(e));
                            }
                        );
                    }

                    const ticketOpenedEmbed = new Discord.EmbedBuilder()
                        .setColor(
                            ticketType.color ? ticketType.color : client.config.mainColor
                        )
                        .setTitle(
                            client.embeds.ticketOpened.title.replace(
                                "CATEGORYNAME",
                                ticketType.name
                            )
                        )
                        .setDescription(
                            ticketType.customDescription ? ticketType.customDescription
                                .replace("CATEGORYNAME", ticketType.name)
                                .replace("USERNAME", interaction.user.username)
                                .replace("USERID", interaction.user.id)
                                .replace("TICKETCOUNT", (await client.db.get("temp.ticketCount")) || 0)
                                .replace("REASON1", reason[0])
                                .replace("REASON2", reason[1])
                                .replace("REASON3", reason[2])
                                .replace("REASON4", reason[3])
                                .replace("REASON5", reason[4])
                                .replace("REASON6", reason[5])
                                .replace("REASON7", reason[6])
                                .replace("REASON8", reason[7])
                                .replace("REASON9", reason[8]) :
                                client.embeds.ticketOpened.description
                                    .replace("CATEGORYNAME", ticketType.name)
                                    .replace("USERNAME", interaction.user.username)
                                    .replace("USERID", interaction.user.id)
                                    .replace("TICKETCOUNT", (await client.db.get("temp.ticketCount")) || 0)
                                    .replace("REASON1", reason[0])
                                    .replace("REASON2", reason[1])
                                    .replace("REASON3", reason[2])
                                    .replace("REASON4", reason[3])
                                    .replace("REASON5", reason[4])
                                    .replace("REASON6", reason[5])
                                    .replace("REASON7", reason[6])
                                    .replace("REASON8", reason[7])
                                    .replace("REASON9", reason[8]))
                    /*
                Copyright 2023 Sayrix (github.com/Sayrix)

                Licensed under the Apache License, Version 2.0 (the "License");
                you may not use this file except in compliance with the License.
                You may obtain a copy of the License at

                    http://www.apache.org/licenses/LICENSE-2.0

                Unless required by applicable law or agreed to in writing, software
                distributed under the License is distributed on an "AS IS" BASIS,
                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                See the License for the specific language governing permissions and
                limitations under the License.
                */
                        .setFooter({
                            // Please respect the project by keeping the credits, (if it is too disturbing you can credit me in the "about me" of the bot discord)
                            text:
                "FlinchMC" +
                client.embeds.ticketOpened.footer.text.replace(
                    "FlinchMC",
                    ""
                ), // Please respect the LICENSE :D
                            // Please respect the project by keeping the credits, (if it is too disturbing you can credit me in the "about me" of the bot discord)
                            iconUrl: client.embeds.ticketOpened.footer.iconUrl,
                        });
                    /*
                Copyright 2023 Sayrix (github.com/Sayrix)

                Licensed under the Apache License, Version 2.0 (the "License");
                you may not use this file except in compliance with the License.
                You may obtain a copy of the License at

                    http://www.apache.org/licenses/LICENSE-2.0

                Unless required by applicable law or agreed to in writing, software
                distributed under the License is distributed on an "AS IS" BASIS,
                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                See the License for the specific language governing permissions and
                limitations under the License.
                */
                    const row = new Discord.ActionRowBuilder();

                    if (client.config.closeButton) {
                        if (client.config.askReasonWhenClosing) {
                            row.addComponents(
                                new Discord.ButtonBuilder()
                                    .setCustomId("close_askReason")
                                    .setLabel(client.locales.buttons.close.label)
                                    .setEmoji(client.locales.buttons.close.emoji)
                                    .setStyle(Discord.ButtonStyle.Danger)
                            );
                        } else {
                            row.addComponents(
                                new Discord.ButtonBuilder()
                                    .setCustomId("close")
                                    .setLabel(client.locales.buttons.close.label)
                                    .setEmoji(client.locales.buttons.close.emoji)
                                    .setStyle(Discord.ButtonStyle.Danger)
                            );
                        }
                    }

                    if (client.config.claimButton) {
                        row.addComponents(
                            new Discord.ButtonBuilder()
                                .setCustomId("claim")
                                .setLabel(client.locales.buttons.claim.label)
                                .setEmoji(client.locales.buttons.claim.emoji)
                                .setStyle(Discord.ButtonStyle.Primary)
                        );
                    }

                    const body = {
                        embeds: [ticketOpenedEmbed],
                        content: `<@${interaction.user.id}> ${
                            client.config.pingRoleWhenOpened
                                ? client.config.roleToPingWhenOpenedId
                                    .map((x) => `<@&${x}>`)
                                    .join(", ")
                                : ""
                        }`,
                    };

                    if (row.components.length > 0) body.components = [row];

                    channel
                        .send(body)
                        .then((msg) => {
                            client.db.set(`tickets_${channel.id}.messageId`, msg.id);
                            msg.pin().then(() => {
                                msg.channel.bulkDelete(1);
                            });
                            interaction
                                .editReply({
                                    content: client.locales.ticketOpenedMessage.replace(
                                        "TICKETCHANNEL",
                                        `<#${channel.id}>`
                                    ),
                                    components: [],
                                    ephemeral: true,
                                })
                                .catch((e) => console.log(e));
                        })
                        .catch((e) => console.log(e));
                });
        }

        if (interaction.isButton()) {
            if (interaction.customId === "openTicket") {
                await interaction
                    .deferReply({ ephemeral: true })
                    .catch((e) => console.log(e));

                // Max ticket opened

                for (let role of client.config.rolesWhoCanNotCreateTickets) {
                    if (role && interaction.member.roles.cache.has(role)) {
                        return interaction
                            .editReply({
                                content:
                  "You can't create a ticket because you are blacklisted",
                                ephemeral: true,
                            }).catch((e) => console.log(e));
                    }
                }

                const all = (await client.db.all()).filter((data) =>
                    data.id.startsWith("tickets_")
                );
                const ticketsOpened = all.filter(
                    (data) =>
                        data.value.creator === interaction.user.id &&
            data.value.closed === false
                ).length;
                if (client.config.maxTicketOpened !== 0) {
                    // If maxTicketOpened is 0, it means that there is no limit
                    if (
                        ticketsOpened > client.config.maxTicketOpened ||
            ticketsOpened === client.config.maxTicketOpened
                    ) {
                        return interaction
                            .editReply({
                                content: client.locales.ticketLimitReached.replace(
                                    "TICKETLIMIT",
                                    client.config.maxTicketOpened
                                ),
                                ephemeral: true,
                            })
                            .catch((e) => console.log(e));
                    }
                }

                // Make a select menus of all tickets types

                const row = new Discord.ActionRowBuilder().addComponents(
                    new Discord.StringSelectMenuBuilder()
                        .setCustomId("selectTicketType")
                        .setPlaceholder(client.locales.other.selectTicketTypePlaceholder)
                        .setMaxValues(1)
                        .addOptions(
                            client.config.ticketTypes.map((x) => {
                                const a = {
                                    label: x.name,
                                    value: x.codeName,
                                };
                                if (x.description) a.description = x.description;
                                if (x.emoji) a.emoji = x.emoji;
                                return a;
                            })
                        )
                );

                interaction
                    .editReply({
                        ephemeral: true,
                        components: [row],
                    })
                    .catch((e) => console.log(e));
            }

            if (interaction.customId === "claim") {
                const { claim } = require("../utils/claim.js");
                claim(interaction, client);
            }

            if (interaction.customId === "close") {
                await interaction
                    .deferReply({ ephemeral: true })
                    .catch((e) => console.log(e));
                const { close } = require("../utils/close.js");
                close(interaction, client, client.locales.other.noReasonGiven);
            }

            if (interaction.customId === "close_askReason") {
                const { closeAskReason } = require("../utils/close_askReason.js");
                closeAskReason(interaction, client);
            }

            if (interaction.customId === "deleteTicket") {
                const { deleteTicket } = require("../utils/delete.js");
                deleteTicket(interaction, client);
            }
        }

        if (interaction.isStringSelectMenu()) {
            if (interaction.customId === "selectTicketType") {
                const all = (await client.db.all()).filter((data) =>
                    data.id.startsWith("tickets_")
                );
                const ticketsOpened = all.filter(
                    (data) =>
                        data.value.creator === interaction.user.id &&
            data.value.closed === false
                ).length;
                if (client.config.maxTicketOpened !== 0) {
                    // If maxTicketOpened is 0, it means that there is no limit
                    if (
                        ticketsOpened > client.config.maxTicketOpened ||
            ticketsOpened === client.config.maxTicketOpened
                    ) {
                        return interaction
                            .reply({
                                content: client.locales.ticketLimitReached.replace(
                                    "TICKETLIMIT",
                                    client.config.maxTicketOpened
                                ),
                                ephemeral: true,
                            })
                            .catch((e) => console.log(e));
                    }
                }

                const ticketType = client.config.ticketTypes.find(
                    (x) => x.codeName === interaction.values[0]
                );
                if (!ticketType)
                    return console.error(
                        `Ticket type ${interaction.values[0]} not found!`
                    );
                if (ticketType.askQuestions) {
                    const modal = new client.discord.ModalBuilder()
                        .setCustomId("askReason")
                        .setTitle(client.locales.modals.reasonTicketOpen.title);

                    ticketType.questions.forEach((x, i) => {
                        const input = new client.discord.TextInputBuilder()
                            .setCustomId(`input_${interaction.values[0]}_${i}`)
                            .setLabel(x.label)
                            .setStyle(x.style == "SHORT" ? client.discord.TextInputStyle.Short : client.discord.TextInputStyle.Paragraph)
                            .setPlaceholder(x.placeholder)
                            .setMaxLength(x.maxLength);
                        
                        const firstActionRow = new client.discord.ActionRowBuilder().addComponents(input);
                        modal.addComponents(firstActionRow);
                    });

                    await interaction.showModal(modal).catch(e => console.log(e));
                } else {
                    createTicket(ticketType, client.locales.other.noReasonGiven);
                }
            }

            if (interaction.customId === "removeUser") {
                const ticket = await client.db.get(
                    `tickets_${interaction.message.channelId}`
                );
                client.db.pull(
                    `tickets_${interaction.message.channel.id}.invited`,
                    interaction.values
                );

                interaction.values.forEach((value) => {
                    interaction.channel.permissionOverwrites
                        .delete(value)
                        .catch((e) => console.log(e));

                    client.log(
                        "userRemoved",
                        {
                            user: {
                                tag: interaction.user.tag,
                                id: interaction.user.id,
                                avatarURL: interaction.user.displayAvatarURL(),
                            },
                            ticketId: ticket.id,
                            ticketChannelId: interaction.channel.id,
                            removed: {
                                id: value,
                            },
                        },
                        client
                    );
                });

                interaction
                    .update({
                        content: `> Removed ${
                            interaction.values.length < 1
                                ? interaction.values
                                : interaction.values.map((a) => `<@${a}>`).join(", ")
                        } from the ticket`,
                        components: [],
                    })
                    .catch((e) => console.log(e));
            }
        }

        if (interaction.isModalSubmit()) {
            if (interaction.customId === "askReason") {
                const type = interaction.fields.fields.first().customId.split("_")[1];
                const ticketType = client.config.ticketTypes.find(
                    (x) => x.codeName === type
                );
                if (!ticketType)
                    return console.error(
                        `Ticket type ${interaction.values[0]} not found!`
                    );
                createTicket(ticketType, interaction.fields.fields);
            }

            if (interaction.customId === "askReasonClose") {
                await interaction.deferReply().catch((e) => console.log(e));
                const { close } = require("../utils/close.js");
                close(interaction, client, interaction.fields.fields.first().value);
            }
        }
    },
};

/*
Copyright 2023 Sayrix (github.com/Sayrix)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
node.js error-handling discord bots digital-ocean
© www.soinside.com 2019 - 2024. All rights reserved.