# Examples

{% hint style="info" %}
The code below demonstrates the difference in how to capture an user using discord.js and djs-protofy
{% endhint %}

## Getting an user with discord.js

{% code overflow="wrap" %}

```javascript
// Getting an user with GlobalName
<Client>.users.cache.find(user => user.globalName === string);

// Getting an user with Shard BroadcastEval
<Client>.shard.broadcastEval((shard, string) =>
  shard.users.cache.get(string), { context: string })
  .then(res => res.find(Boolean))
  .catch(error => console.log(error));
  
// Searching an user with a string
<Guild>.members.cache.find(member => {
    return member.id === string
       || member.displayName === string
       || member.globalName === string
       || member.nickname === string
       || member.user.globalName === string
       || member.user.username === string
});
```

{% endcode %}

## Getting an user with djs-protofy

```javascript
// Getting an user with GlobalName
<Client>.users.getByGlobalName(string | RegExp);

// Getting an user with Shard BroadcastEval
<Client>.users.getInShardsById(string);

// Searching an user with a string
<Guild>.members.searchBy(string | RegExp);
// OR
<Guild>.members.searchBy({
  id?: string
  displayName?: string | RegExp
  globalName?: string | RegExp
  nickname?: string | RegExp
  username?: string | RegExp
}); 
```
