简体   繁体   English

类型错误:无法读取未定义的属性(读取“发送”)

[英]TypeError: Cannot read properties of undefined (reading 'send')

I am getting the following error using discord.js V14: TypeError: Cannot read properties of undefined (reading 'send')我在使用 discord.js V14 时收到以下错误:类型错误:无法读取未定义的属性(读取“发送”)

Thank you to anyone who can help me.感谢任何能帮助我的人。

const { Client, Message, MessageEmbed } = require("discord.js");
const {SlashCommandBuilder} = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('test')
        .setDescription('this is a test thing'),
    /**
    * @parom {Client} client
    * @parom {Message} message
    * @parom {String[]} args
    */
     async execute(client, message, args, interaction) {
        const questions = [
            "test",
            "test1?"
        ];
          
        let collectCounter = 0;
        let endCounter = 0;
        
        const filter = (m) => m.author.id === message.author.id;
        const author = message.author;
        const appStart = await author.send(questions[collectCounter++]);
        const channel = appStart.channel;
        
        const collector = channel.createMessageCollector(filter);
        message.delete({timeout: 100})

        collector.on("collect", () => {
            if (collectCounter < questions.length) {
                channel.send(questions[collectCounter++]);
            } else {
                channel.send("submited!");
                collector.stop("fulfilled");
            }
        });

        const appsChannel = client.channels.cache.get("976110575547482152");
        collector.on("end", (collected, reason) =>{
            if (reason === "fulfilled") {
                let index = 1;
                const mappedResponses = collected
                    .map((msg) => { 
                        return `${index++}) ${questions[endCounter++]}\n-> ${msg.content}`;
                    })
                    .join("\n\n");
                        
                appsChannel.send(
                    new MessageEmbed()
                        .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true}))
                        .setTitle("!New Report!")
                        .setDescription(mappedResponses)
                        .setColor(`RANDOM`)
                        .setTimestamp()

                );
                appsChannel.send(`<@1057374161846145076>`);
            }
        });
    },
};

Note I was using this before and once I updated to V14 I started getting this error.请注意,我之前使用过这个,一旦我更新到 V14,我就开始收到这个错误。 it should message the user the set questions then post the answers in a channel.它应该向用户发送设置问题的消息,然后在频道中发布答案。

EDIT: I am getting the error on this line编辑:我在这条线上收到错误

const appStart = await author.send(questions[collectCounter++]);

My interactions.js file我的 interactions.js 文件

module.exports = {
    name: "interactionCreate",
    async execute(interaction, client) {
        if (interaction.isChatInputCommand()) {
            const {commands} = client;
            const {commandName} = interaction;
            const command = commands.get(commandName);
            if (!command) return;

            try {
                await command.execute(interaction, client);
            } catch (error) {
              console.error(error);
              await interaction.reply({
                content: `Something went wrong while executing this command...`,
                ephemeral: true,
              });
                
            }
        } else if (interaction.isButton()) {
          const {buttons} = client;
          const {customId} = interaction;
          const button = buttons.get(customId);
          if (!button) return new Error('This Button Does not exist');

          try{
            await button.execute(interaction, client);
          } catch (err) {
            console.error(err);
          }
        }
    },
};

You're calling the execute method of your /test command file with (interaction, client) but the method expects (client, message, args, interaction) .您正在使用(interaction, client)调用/test命令文件的执行方法,但该方法需要(client, message, args, interaction)

A possible solution would be to change the /test command file to一个可能的解决方案是将/test命令文件更改为

// Optimized imports
const { Client, MessageEmbed, BaseInteraction,
     SlashCommandBuilder } = require("discord.js");

module.exports = {
    data: new SlashCommandBuilder()
        .setName('test')
        .setDescription('this is a test thing'),
    // Fixed typo in @param
    /**
    * @param {Client} client
    * @param {BaseInteraction} interaction
    */
    async execute(interaction, client) {
        const questions = [
            "test",
            "test1?"
        ];

        let collectCounter = 0;
        let endCounter = 0;

        // Get "Author" from interaction
        const author = interaction.user;
        const filter = (m) => m.author.id === author.id;
        const appStart = await author.send(questions[collectCounter++]);
        const channel = appStart.channel;

        const collector = channel.createMessageCollector(filter);
        // Removed message.delete() because interactions aren't messages and cant be deleted.

        collector.on("collect", () => {
            if (collectCounter < questions.length) {
                channel.send(questions[collectCounter++]);
            } else {
                channel.send("submited!");
                collector.stop("fulfilled");
            }
        });

        const appsChannel = client.channels.cache.get("976110575547482152");
        collector.on("end", (collected, reason) => {
            if (reason === "fulfilled") {
                let index = 1;
                const mappedResponses = collected
                    .map((msg) => {
                        return `${index++}) ${questions[endCounter++]}\n-> ${msg.content}`;
                    })
                    .join("\n\n");

                appsChannel.send(
                    new MessageEmbed()
                        .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
                        .setTitle("!New Report!")
                        .setDescription(mappedResponses)
                        .setColor(`RANDOM`)
                        .setTimestamp()

                );
                appsChannel.send(`<@1057374161846145076>`);
            }
        });
    },
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法读取未定义的属性(读取“发送”) - TypeError: Cannot read properties of undefined (reading 'send') 类型错误:无法读取 discord.js 中未定义的属性(读取“发送”) - TypeError: Cannot read properties of undefined (reading 'send') in discord.js 笑话错误:TypeError:无法读取未定义的属性(读取“发送”) - Jest error: TypeError: Cannot read properties of undefined (reading 'send') TypeError:无法读取未定义的属性(读取“forEach”) - TypeError: Cannot read properties of undefined (reading 'forEach') TypeError:无法读取未定义的属性(读取&#39;indexOf&#39;) - TypeError: Cannot read properties of undefined (reading 'indexOf') TypeError:无法读取未定义的属性(读取&#39;forEach) - TypeError: Cannot read properties of undefined (reading 'forEach) TypeError:无法读取未定义的属性(读取“命令”) - TypeError: Cannot read properties of undefined (reading 'commands') TypeError:无法读取未定义的属性(读取“最高”) - TypeError: Cannot read properties of undefined (reading ‘highest’) TypeError:无法读取未定义的属性(读取“findOne”) - TypeError: Cannot read properties of undefined (reading 'findOne') TypeError:无法读取未定义的属性(读取“useParams”) - TypeError: Cannot read properties of undefined (reading 'useParams')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM