Skip to content
SQKo edited this page Dec 9, 2023 · 3 revisions

Bans are part of Guild (Server).

use Discord\Parts\Guild\Ban;

A Ban is a ban on a user specific to a guild. It is also IP based.

Requires GUILDS intent

GUILD_BAN_ADD

GUILD_BAN_REMOVE


Ban a Member

Your BOT must have ban_members permission

You must first get the Guild object and the Member object to use the code below

Ban the $member with reason "bad person" and delete their messages from 5 days back:

$member->ban(5, 'bad person')->then(function (Ban $ban) {
    // ...
})->done();

https://discord.com/developers/docs/resources/guild#create-guild-ban

Unban an User

Your BOT must have ban_members permission

You must first get the Guild object and the User object or User ID to use the code below

Unban with $user object:

$guild->unban($user)->then(function () {
    // ...
})->done();

Or, change 123123123123123123 below with the User ID:

$guild->unban('123123123123123123')->then(function () {
    // ...
})->done();

https://discord.com/developers/docs/resources/guild#remove-guild-ban

Get a Specific Ban

Retrieving a ban requires GUILD_BANS intent and ban_members permission

You must first get the Guild object to use the code below. Change 123123123123123123 below with the User ID you want to retrieve

Cached, synchronous (i.e retrieveBans option is true):

$ban = $guild->bans->get('user_id', '123123123123123123');

If the code above returns null, you may need to fetch it first (Promise, asynchronous):

$guild->bans->fetch('123123123123123123')->then(function (Ban $ban) {
    // ...
})->done();

https://discord.com/developers/docs/resources/guild#get-guild-ban

Clone this wiki locally