找不到消息作者

xurqigkl  于 2021-09-13  发布在  Java
关注(0)|答案(2)|浏览(369)

在这行代码中,我试图将私人消息发送给初始消息作者。由于未知原因,出现错误:
(节点:17560)未处理的PromisejectionWarning:typeerror:无法读取未定义的属性“send”
这是一行代码:

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

以下是整个文件:

const Discord = require("discord.js");
const {Client, Message, MessageEmbed} = require("discord.js");
module.exports = {
    name: 'apply',
    /**
     * 
     * @param {Client} client 
     * @param {Messafe} message 
     * @param {String[]} args 
     */
    run : async(client, message, args) => {
        const questions = [
            "What is your in-game name?",
            "Do you accept the rules?",
            "How old are you?",
            "Where are you from?",
            "How long have you been playing Minecraft?",
            "Where did you find the server?",
            "Have you ever been banned from another server on Minecraft? If yes, what was the reason?",
            "Why should we accept you?",
        ]
        let collectCounter = 0;
        let endCounter = 0;

        const filter = (m) => m.author.id === message.author.id;

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

        const collector = channel.createMessageCollector(filter);

        collector.on("collect", () => {
            if(collectCounter < questions.length) {
                channel.send(questions[collectedCounter++]);
            } else {
                channel.send("Your application has been sent!");
                collector.stop("fulfilled");
            }
        });

        const appsChannel = client.channel.cache.get('863534867668009004');
        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(message.channel.send('New Application!', mappedResponses));
        });
    },
};

这是我的index.js:

const fs = require("fs");
const Discord = require("discord.js");

const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

const BOT_ID = "863550035923697674";

const prefix = "!";

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);
  client.user.setActivity("ur cheat files...", {
    type: "WATCHING",
    url: "https://discord.gg/bzYXx8t3fE"
  });
});

for(const file of commandFiles) {
  const command = require(`./commands/${file}`);
  client.commands.set(command.name, command);
}

client.on("message", message => {
  let userID = message.author.id;
  if (userID == BOT_ID) {
    return;
  }
  const version = "Wersja bota 0.2";
  ///const args = message.content;
  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();
  if(!client.commands.has(command)) return;
  try{
      client.commands.get(command).run(message, args);
  }catch(error){
      console.error(error);
      message.reply('**There was an issue executing that command!**');
  }
});

client.login("tokenishere");

谢谢你的帮助!

tv6aics1

tv6aics11#

这只是意味着 message 不是你想象的那样。在命令处理程序中,使用参数执行命令 messageargs (命令事项)。但是,在命令文件中,您希望参数为 client , message ,然后 args .
这意味着,在您的命令文件中, client 实际上是指这个信息,, message 实际上是指参数,第三个参数不存在。
要解决此问题,可以修改任一文件中参数的名称和顺序。

aiazj4mn

aiazj4mn2#

这是一个简单的解决方案。。。正如@lioness100提到的,您的参数是错误的,我在这里展示一个代码示例
在中找到这行代码 index.js :

client.commands.get(command).run(message, args);
// and change it to
client.commands.get(command).run(message, args, client);

之后,转到您的“文件”并修改这行代码:

run : async(client, message, args) => {
// And change it to
run : async(message, args) => {

您的问题是您在“文件”中执行了错误的参数,所以您只需要从 client, message, argsmessage, args 这是一个常见的错误

相关问题