# Ban, unban & kick server members

## How to do it?

#### To ban, unban or kick a server member, you either have to get the Member component that is linked to the user you'd like to perform an action on or you can also do it directly using the appropriate REST method.

## Method 1

For example, if the member swears, you can directly get their Member component and ban them within the "messageCreate" event.

[Make sure to enable the GUILD\_MESSAGES and MESSAGE\_CONTENT intents](https://guide.touchguild.com/intents) to detect messages that have been created as well as their content.

```typescript
client.on("messageCreate", async message => {
  // Get the server member.
  const member = await message.member;
  if (member?.app) return;
  if (message.content?.includes("damn")) {
    void member?.ban(); // Use Member#ban method to ban the user from the server.
  }
});
```

You can also get the component in other ways by using different events or get the Member component by using REST methods such as getMember or the cache-only method located in the Client.

```typescript
client.getMember(guildID, memberID); // Cache-only method
```

```typescript
client.rest.guilds.getMember(guildID, memberID); // REST method
```

and apply the ban accordingly using the Member#ban method, this is the same way for unban, and kick as you can use Member#unban and Member#kick

These are the methods you can use using the Member component:

```typescript
Member.ban(reason?);
```

```typescript
Member.unban();
```

```typescript
Member.kick();
```

## Method 2

#### You can also use directly the REST method to ban, unban or kick a server member.

### Ban

```typescript
client.rest.guilds.createBan(guildID, memberID, reason?);
```

### Unban

```typescript
client.rest.guilds.removeBan(guildID, memberID);
```
