【问题标题】:DeprecationWarning: Collection#find: pass a function insteadDeprecationWarning: Collection#find: 传递一个函数
【发布时间】:2019-02-01 05:21:37
【问题描述】:

我是 node.js 的新手,我目前正在使用 discord.js 来制作 Discord 机器人。一旦使用任何 bot 命令,控制台就会打印出 DeprecationWarning。 例如:

(node:15656) DeprecationWarning: Collection#find: pass a function instead

(node:15656) 有时是另一个数字,几乎总是在变化。
这就是我的代码的样子(只有一个命令,我有多个命令,不过我都收到了这个错误):

const botconfig = require("./botconfig.json")
const Discord = require("discord.js");
const bot = new Discord.Client();

bot.on("ready", () => { 
    console.log(`Launched ${bot.user.username}...`);
    bot.user.setActivity("Games", { type: "PLAYING" });
});

bot.on("message", async message => {
    if (message.author.bot) return;

    let prefix = botconfig.prefix;
    let messageArray = message.content.split(" ");
    let cmd = messageArray[0];
    let args = messageArray.slice(1);
    let botico = bot.user.displayAvatarURL;

    if (cmd == `${prefix}help`) {
        let helpEmbed = new Discord.RichEmbed()
            .addField(".kick", "kick a user", true)
            .addField(".ban", "ban a user", true)
            .addField(".unban", "unbans a user", true)
            .addField(".mute", "mutes a user over a period of time", true)
            .setColor("#005b5f")
            .setThumbnail(botico);

        message.channel.send(helpEmbed);
        console.log(`command used: help`);
    };
});

bot.login(botconfig.token)

【问题讨论】:

  • 通常,最好不要发布整个代码,因为它可能无关紧要,但在这种情况下,最好将其全部发布:在代码中的某个地方,您调用了 .find() 但在此部分代码它不会出现在任何地方。尝试在您的代码中搜索.find(),然后发布该部分;)

标签: javascript node.js discord discord.js


【解决方案1】:

它在您的其他命令之一中。您很可能在其他命令之一中使用 #Collection.find('name', 'keyname') 之类的东西。

已更新为#Collection.find(x => x.name === "name")

就像它在错误中所说的那样。 #Collection.find() 需要一个函数。所以使用一个,错误就会消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2019-02-14
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    相关资源
    最近更新 更多