Operators of an open or group channel can remove any users that behave inappropriately in the channel using the ban feature. A banned user is immediately kicked out of the channel, but allowed to participate in the channel again after the time specified in the seconds property has passed. Operators can ban and unban users using the following code.
try {
final channel = await OpenChannel.getChannel(CHANNEL_URL);
// Ban a user.
await channel.banUser(USER_ID, seconds: SECONDS);
// The user is successfully banned from the channel.
// You can display a message to let the user know they have been banned.
// Unban a user.
await channel.unbanUser(USER_ID);
// The user is successfully unbanned from the channel.
// You can display a message to let the user know they have been unbanned.
} catch (e) {
// Handle error.
}
try {
await groupChannel.banUser(
userId: USER_ID,
seconds: SECONDS,
description: DESCRIPTION
);
// The user is successfully banned from the channel.
// You can display a message to let the user know they have been banned.
await groupChannel.unbanUser(userId: USER_ID);
// The user is successfully unbanned.
// You can display a message to let the user know they have been unbanned.
} catch (e) {
// Handle error.
}