👥Users
Prototypes from UserManager
Getting a user by ID
// discord.js
<Client>.users.cache.get(string);
// djs-protofy
<Client>.users.getById(string); // User | undefined
Getting a user by Display Name
// discord.js
<Client>.users.cache.find(user => user.displayName === string);
// djs-protofy
<Client>.users.getByDisplayName(string | RegExp); // User | undefined
Getting a user by Global Name
// discord.js
<Client>.users.cache.find(user => user.globalName === string);
// djs-protofy
<Client>.users.getByGlobalName(string | RegExp); // User | undefined
Getting a user by Username
// discord.js
<Client>.users.cache.find(user => user.username === "username");
// djs-protofy
<Client>.users.getByUsername(string | RegExp); // User | undefined
Getting a user in another Shard with ID
// discord.js
await <Client>.shard.broadcastEval((shard) =>
shard.users.cache.get(string))
.then(res => res.find(Boolean))
.catch(error => console.log(error));
// djs-protofy
await <Client>.users.getInShardsById(string); // Promise<User | undefined>
// OR
await <Client>.users.getInShardsById(string, boolean); // Promise<APIUser | User | undefined>
Getting a user in another Shard with Display Name
// discord.js
await <Client>.shard.broadcastEval((shard) =>
shard.users.cache.find(user => user.displayName === string))
.then(res => res.find(Boolean))
.catch(error => console.log(error));
// djs-protofy
await <Client>.users.getInShardsByDisplayName(string | RegExp); // Promise<User | null>
// OR
await <Client>.users.getInShardsByDisplayName(string | RegExp, boolean); // Promise<APIUser | User | null>
Getting a user in another Shard with Global Name
// discord.js
await <Client>.shard.broadcastEval((shard) =>
shard.users.cache.find(user => user.globalName === string))
.then(res => res.find(Boolean))
.catch(error => console.log(error));
// djs-protofy
await <Client>.users.getInShardsByGlobalName(string | RegExp); // Promise<User | null>
// OR
await <Client>.users.getInShardsByGlobalName(string | RegExp, boolean); // Promise<APIUser | User | null>
Getting a user in another Shard with Username
// discord.js
await <Client>.shard.broadcastEval((shard) =>
shard.users.cache.find(user => user.username === string))
.then(res => res.find(Boolean))
.catch(error => console.log(error));
// djs-protofy
await <Client>.users.getInShardsByUsername(string | RegExp); // Promise<User| null>
// OR
await <Client>.users.getInShardsByUsername(string | RegExp, boolean) // Promise<APIUser | User | null>
Searching for a user
// discord.js
<Client>.users.cache.find(user => {
return user.id === string
|| user.displayName === string
|| user.globalName === string
|| user.username === string
});
// djs-protofy
<Client>.users.searchBy(string); // User | undefined
// OR
<Client>.users.searchBy(string[]); // Collection<string, User>
If you use an array of String, you will receive a Collection instead of User
Last updated