cmd.user.ban
Bans a user from the guild. Works whether or not the user is currently a member.
JavaScript
const { cmd } = require("syntx.js");
await cmd.user.ban({ user, reason, deleteMessageDays }, message);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
user | string | discord.js User | Yes | The user ID or user object to ban. |
reason | string | No | Audit log reason for the ban. |
deleteMessageDays | number | No | Number of days of messages to delete. Must be between 0 and 7. Defaults to 0. |
message | discord.js Message | Interaction | Yes | A guild message or interaction, used to access the guild. |
Returns
The result of the Discord ban API call.
Example
JavaScript
client.command({
name: "ban",
content: async (message) => {
const id = cmd.message.mentioned(message, 1);
if (!id) return message.reply("Please mention a user.");
await cmd.user.ban(
{
user: id,
reason: "Violated server rules",
deleteMessageDays: 1,
},
message
);
message.reply(`<@${id}> has been banned.`);
},
});Warning
The bot must have the Ban Members permission, and its highest role must be above the target's highest role. If the target is not bannable, a SyntxError is thrown.