Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I check if a user is banned or not in DiscordJS V14?

So I want to fetch banned members in DiscordJS V14, but the old method doesn’t work.

My code:

const { EmbedBuilder } = require("discord.js");
const { colors } = require("discordjs-colors-bundle");

module.exports = {
  config: {
    name: "unban",
    description: "Unban a member from the guild",
    usage: "unban [id]",
  },
  permissions: ["BanMembers"],
  owner: false,
  run: async (client, message, args, prefix, config, db) => {
    const userId = args.join(" ");

    if (!userId) {
      return message.reply({ content: `:x: | Please provide a ID to ban! ` });
    }

    const banList = await message.guild.fetchBans();
    const bannedUser = banList.find((user) => user.id === userId);

    const UnbannedEmbed = new EmbedBuilder()
      .setColor(colors.SeaBlue)
      .setTitle(`Unbanned`)
      .setDescription(`The user is unbanned!`)
      .setTimestamp()
      .setFooter({ text: `${message.guild.name}` });

    if (bannedUser) {
      message.guild.members.unban(userId);
      message.reply({ embeds: [UnbannedEmbed] });
    } else {
      message.reply({ content: `:x: | The mentioned user is not banned!` });
    }
  },
};

The error I get:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TypeError: message.guild.fetchBans is not a function Promise { <rejected> TypeError: message.guild.fetchBans is not a function

I was expecting that if the user is banned then it’ll unban the user, else it’ll return an error message to the Discord user

>Solution :

Check the docs.

The function you can use to fetch the bans is:

const banList = await message.guild.bans.fetch();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading