javascript DeprecationWarning: Collection#find: 传递一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52026292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DeprecationWarning: Collection#find: pass a function instead
提问by pnda
I'm quite a newbie to node.js and I'm currently using discord.js to make a Discord bot. As soon as any bot command gets used the console prints a DeprecationWarning. for example:
我是 node.js 的新手,我目前正在使用 discord.js 制作一个 Discord 机器人。一旦使用任何机器人命令,控制台就会打印一条 DeprecationWarning。例如:
(node:15656) DeprecationWarning: Collection#find: pass a function instead
(node:15656)sometimes is another number, nearly always changing.
This is what my code looks like (only one command, I've got multiple, I get this error with all of them though):
(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)
回答by NealC
It is in one of your other commands. You more than likely are using something like #Collection.find('name', 'keyname')in one of the other commands.
它在您的其他命令之一中。您很可能正在使用#Collection.find('name', 'keyname')其他命令之一中的类似内容。
This has been updated to #Collection.find(x => x.name === "name").
这已更新为#Collection.find(x => x.name === "name").
Like it says in the error. #Collection.find() requires a function instead. So use one and the error goes away.
就像错误中所说的那样。#Collection.find() 需要一个函数。所以使用一个,错误就会消失。

