Skip to content
Advertisement

how to add reason in discord.js ban and kick command with commando framework?

I’m currently working on a discord.js bot with commando (which is the official framework/commands handler from the discord.js creator)
I have researched this subject on various websites and nothing seems to work with my commando framework.
This is the code

const Commando = require("discord.js-commando");

module.exports = class banCommands extends (
  Commando.Command
) {
  constructor(client) {
    super(client, {
      name: "ban",
      aliases: ["bans"],
      group: "general",
      memberName: "ban",
      description: "Banned the mention member from the server",
    });
  }
  run(message) {
    const target = message.mentions.users.first();
    if (!target) {
      message.reply("you need to have at least one users mentioned");
      return;
    }
    const { guild } = message;
    const member = guild.members.cache.get(target.id);
    if (member.bannable) {
      guild.members.ban(member);
      message.reply("That user has been banned");
    } else {
      message.reply("You cannot ban that user.");
      console.log(target);
    }
  }
};

Any suggestion? or anything that have the same subject?

Thank you

Advertisement

Answer

You’ll need to put it in the options argument (see the docs). You should also probably use member.ban instead of guild.members.ban(member), but anyways, here’s an example:

member.ban({
    reason: "Your reason here"
});

And the member will be banned, with the reasoning in audit logs showing up properly. You should add an reason argument to your command as well. Don’t ask me how though, I haven’t touched discord.js in a year and especially not commando. Check the guide for that. Make the mention the first argument and the reason the rest.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement