DeprecationWarning: Collection#find: 传递一个函数

DeprecationWarning: Collection#find: pass a function instead(DeprecationWarning: Collection#find: 传递一个函数)
本文介绍了DeprecationWarning: Collection#find: 传递一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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:15656) DeprecationWarning: Collection#find: pass a function instead

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

(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):

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)

推荐答案

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

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(x => x.name === "name").

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

Like it says in the error. #Collection.find() requires a function instead. So use one and the error goes away.

这篇关于DeprecationWarning: Collection#find: 传递一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
Check if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)