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

ParameterTypeRequiredDescription
userstring | discord.js UserYesThe user ID or user object to ban.
reasonstringNoAudit log reason for the ban.
deleteMessageDaysnumberNoNumber of days of messages to delete. Must be between 0 and 7. Defaults to 0.
messagediscord.js Message | InteractionYesA 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.