首页 > 解决方案 > 如何从缓存中删除用户

问题描述

我正在使用discord.jsv12.3.1


我想知道我应该如何从缓存中删除用户。例如:

// this would successfully get the user data
client.users.cache.get('<ID Here>');

// delete user from cache

// this time it returns undefined, as the user is no longer stored in the cache
client.users.cache.get('<Same ID>');

有什么办法可以做到吗?

标签: javascriptnode.jsdiscord.js

解决方案


discord.js collection .delete()使用该方法从缓存中删除用户、公会、频道、表情符号等非常容易。

使用此方法的一个简单示例:

例子


.delete()true如果找到并删除了该元素,或者false该元素不存在,则将返回。它也等同于Map.prototype.delete()


推荐阅读