在尝试创建一个 ticketTool 命令时出现错误,使用我的 Discord.js v14 机器人。

huangapple go评论65阅读模式
英文:

Error when trying to create a ticketTool command with my discordjs v14 bot

问题

Here's the translated part of your text:

"我正在制作一个ticketTool命令,当我使用该命令时,会出现以下错误:

ReferenceError: create is not defined
at Object.execute (C:\Users\joebo\OneDrive\Desktop\WAIT\commands\ticketTool\createTicketEmbed.js:44:19)
at Object.execute (C:\Users\joebo\OneDrive\Desktop\WAIT\events\interaction-create.js:16:18)
at Client. (C:\Users\joebo\OneDrive\Desktop\WAIT\index.js:76:44)
at Client.emit (node:events:525:35)
at InteractionCreateAction.handle (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:494:22)
at WebSocketShard.onMessage (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
at callListener (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\ws\lib\event-target.js:290:14)
ReferenceError: create is not defined
at Object.execute (C:\Users\joebo\OneDrive\Desktop\WAIT\commands\ticketTool\createTicketEmbed.js:44:19)
at Client. (C:\Users\joebo\OneDrive\Desktop\WAIT\index.js:90:17)
at Client.emit (node:events:525:35)
at InteractionCreateAction.handle (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:494:22)
at WebSocketShard.onMessage (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
at callListener (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\ws\lib\event-target.js:290:14)
at WebSocket.onMessage (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\ws\lib\event-target.js:209:9)
node:events:491
throw er; // Unhandled 'error' event
^

DiscordAPIError[10062]: Unknown interaction
at handleErrors (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules@discordjs\rest\dist\index.js:736:23)
at async REST.request (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules@discordjs\rest\dist\index.js:1387:22)
at async ChatInputCommandInteraction.reply (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Client. (C:\Users\joebo\OneDrive\Desktop\WAIT\index.js:96:4)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: 'There was an error while executing this command!',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1104799756888309820/aW50ZXJhY3Rpb246MTEwNDc5OTc1Njg4ODMwOTgyMDprRTNWMUY4NzY2R3plZkhBUVF0RFlaR09jcjZvSXhYejZ5dVI1MTZIUE1naGpnYll2ck9Lb3ZZelRuOHExS0hLckd4WlhIbXBEcEpkdzNrRG9wMkxDUks0VTRRbGtYcnZ2SVNIV1AxQTJ6Yll0SVVOMHd1R2NER09teW5jclNIaQ/callback'
}

Node.js v18.16.0"

I've only translated the error messages and relevant code portions. If you have any specific questions or need further assistance, please let me know.

英文:

I am making a ticketTool command, and when I use the command, this error occurs

ReferenceError: create is not defined
    at Object.execute (C:\Users\joebo\OneDrive\Desktop\WAIT\commands\ticketTool\createTicketEmbed.js:44:19)
    at Object.execute (C:\Users\joebo\OneDrive\Desktop\WAIT\events\interaction-create.js:16:18)
    at Client.<anonymous> (C:\Users\joebo\OneDrive\Desktop\WAIT\index.js:76:44)
    at Client.emit (node:events:525:35)
    at InteractionCreateAction.handle (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)        
    at module.exports [as INTERACTION_CREATE] (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)       
    at WebSocketShard.onPacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:494:22)
    at WebSocketShard.onMessage (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
    at callListener (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\ws\lib\event-target.js:290:14)
ReferenceError: create is not defined
    at Object.execute (C:\Users\joebo\OneDrive\Desktop\WAIT\commands\ticketTool\createTicketEmbed.js:44:19)
    at Client.<anonymous> (C:\Users\joebo\OneDrive\Desktop\WAIT\index.js:90:17)
    at Client.emit (node:events:525:35)
    at InteractionCreateAction.handle (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)        
    at module.exports [as INTERACTION_CREATE] (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)       
    at WebSocketShard.onPacket (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:494:22)
    at WebSocketShard.onMessage (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
    at callListener (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\ws\lib\event-target.js:290:14)
    at WebSocket.onMessage (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\ws\lib\event-target.js:209:9)
node:events:491
      throw er; // Unhandled 'error' event
      ^

DiscordAPIError[10062]: Unknown interaction
    at handleErrors (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\@discordjs\rest\dist\index.js:640:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async BurstHandler.runRequest (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\@discordjs\rest\dist\index.js:736:23)
    at async REST.request (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\@discordjs\rest\dist\index.js:1387:22)
    at async ChatInputCommandInteraction.reply (C:\Users\joebo\OneDrive\Desktop\WAIT\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
    at async Client.<anonymous> (C:\Users\joebo\OneDrive\Desktop\WAIT\index.js:96:4)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:394:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
  requestBody: {
    files: [],
    json: {
      type: 4,
      data: {
        content: 'There was an error while executing this command!',
        tts: false,
        nonce: undefined,
        embeds: undefined,
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: 64,
        message_reference: undefined,
        attachments: undefined,
        sticker_ids: undefined,
        thread_name: undefined
      }
    }
  },
  rawError: { message: 'Unknown interaction', code: 10062 },
  code: 10062,
  status: 404,
  method: 'POST',
  url: 'https://discord.com/api/v10/interactions/1104799756888309820/aW50ZXJhY3Rpb246MTEwNDc5OTc1Njg4ODMwOTgyMDprRTNWMUY4NzY2R3plZkhBUVF0RFlhR09jcjZvSXhYejZ5dVI1MTZIUE1naGpnYll2ck9Lb3ZZelRuOHExS0hLckd4V1hIbXBEcEpkdzNrRG9wMkxDUks0VTRRbGtYcnZ2SVNIV1AxQTJ6Yll0SVVOMHd1R2NER09teW5jclNIaQ/callback'
}

Node.js v18.16.0

I am using this code:

const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ButtonStyle, ButtonBuilder, ActionRowBuilder } = require("discord.js");

module.exports = {
    data: new SlashCommandBuilder()
    .setName('create-ticket')
    .setDescription('Creates a ticket')
    .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
    .addChannelOption((option) =>
    option
  .setName('channel')
  .setDescription('The channel you want to send it to or folder')
  .setRequired(true)
)
.addChannelOption((option) =>
    option
    .setName('ticket-folder')
    .setDescription('The folder than you would like the tickets to be created in')
    .setRequired(true)
),





permissionsRequired: [PermissionFlagsBits.ManageMessages],
botPermissions: [PermissionFlagsBits.ManageMessages],

    async execute(interaction) {
        const channel1 = interaction.options.getChannel('channel')
        const ticketFolder = interaction.options.getChannel('ticket-folder')

            const embed1 = new EmbedBuilder()
            .setTitle('Create a ticket')
            .setDescription(`Tap on the button below to create a ticket`)
            .setTimestamp()
            .setColor('Green')

            const ticketButton = new ButtonBuilder()
			.setCustomId('create')
			.setLabel('Create')
			.setStyle(ButtonStyle.Success)
            .setEmoji('📩')
            const row = new ActionRowBuilder()
			.addComponents(create);

            await channel1.send({embeds: [embed1], components: [row]})


            const confirmation = await response.awaitMessageComponent();

            if (confirmation.customId === 'create'){
                const channel = await message.guild.channels.create(`${interaction.member.username} | ticket`, {
                    type: 'text',
                    parent: ticketFolder.id,
                  });
                  await channel.permissionOverwrites.set([
                    {
                      id: guild.roles.everyone, // this sets the default permissions for everyone
                      deny: ['VIEW_CHANNEL'], // deny everyone from viewing the channel
                    },
                    {
                      id: guild.roles.cache.find(role => role.name === 'Moderator'), // replace this with the role ID of your moderators
                      allow: ['MANAGE_CHANNELS', 'MANAGE_MESSAGES', 'VIEW_CHANNEL'], // allow moderators to manage the channel
                    },
                  ]);
                  
            }
            const embed2 = new EmbedBuilder()
            .setTitle('Ticket Created')
            .setDescription(`${interaction.member.username} has created a ticket!\nTap on the close button to close the ticket`)
            .setTimestamp()
            .setAuthor({ name: Guildmember.user.tag, iconURL: Guildmember.user.displayAvatarURL() })
            .setColor('#FF0000')

            const ticketCloseButton = new ButtonBuilder()
			.setCustomId('close')
			.setLabel('Close')
			.setStyle(ButtonStyle.Danger)
            .setEmoji('❌')

            const row1 = new ActionRowBuilder()
			.addComponents(close);

            await channel.send({
                embeds: [embed2],
                components: [row1],
              })

            const confirmation1 = await response.awaitMessageComponent();
             if (confirmation.customId === 'close'){
                const channelDeleteEmbed = new EmbedBuilder()
                .setTitle('Closing Ticket')
                .setDescription('The ticket will close in 5 seconds')
                .setColor('#FF0000')
                .setTimestamp()
                await channel.send({embeds: [channelDeleteEmbed]})
                setTimeout(() => {
                    channel.delete();
                  }, 5000);
             }

  }   
    };

I have deferred in my interactionCreate event:

try {
			interaction.deferReply()
			await command.execute(interaction);
		} catch (error) {
			console.error(`Error executing ${interaction.commandName}`);
			console.error(error);
		}

and I am not using editReply because I am sending in a specific channel.
Does anyone know why I have this error and how I can fix it?

I am making a ticketTool command for my bot and I have the error above, my code is supplied.

答案1

得分: 1

这段代码应该可以作为注释,但我认为这是你在寻找的答案。所以,你的代码如下:

            .setEmoji('🎫')
            const row = new ActionRowBuilder()
            .addComponents(ticketButton);

但似乎在addComponents中的create并不存在,这会导致create is not defined错误,进而导致Unknown interaction错误。

我相当肯定你的意思是.addComponents(ticketButton);而不是.addComponents(create);,所以尝试更改为这样,应该可以解决你的问题!如果有效,请记得点击答案旁边的灰色复选标记,标记你的问题已解决。

英文:

This would work as a comment, but I think it's the answer you're looking for. So, your code says:

            .setEmoji('📩')
            const row = new ActionRowBuilder()
            .addComponents(create);

But it seems like create in addComponents doesn't exist, which leads you to get the create is not defined error, which then leads to the Unknown interaction error.

I'm pretty sure you meant .addComponents(ticketButton); and not .addComponents(create); so try changing it to that and it should fix your issue! If it does, remember to click the grey checkmark next to this answer to mark your question as solved.

huangapple
  • 本文由 发表于 2023年5月7日 01:34:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定