# 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](/intents.md) 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);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide.touchguild.com/managing-members/ban-unban-and-kick-server-members.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
