Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Discord.js mod bot ban command not working

My discord bot's ban command isn't working and is currently giving me this error. My rols id is 853527575317708820 I don't know what I am doing wrong so please help me out

Here is the command :

Server is ready.
TigerShark Community#3557 Has logged in
(node:204) UnhandledPromiseRejectiontarning: DiscordAPTError: T
AEE RS
user_id: Value "<@!856413967595012127>" is not snowflake.
at RequestHandler.execute (/home/Tunner/TSC/node_modules/di
scoxd. js/src/rest/RequestHandler. js:154:13)
at processTicksAndRejections (internal/process/task
§5:97:5) :!
at async RequestHandler.push (/home/zunner/TSC/node
/discord. js/s1c/rest/RequestHandler. js:39:14)

Here is my code :


module.exports = {
  name: 'ban',
  description: "Used to ban members from a server",
  async execute(client, message, args, Discord) {

    if (!(message.member.roles.cache.some(r => r.id === "853527575317708820"))) return

      let reason;
      const user = await client.users.fetch(args[0])
      if (!args[1])
      {
        reason = "Not specified"
      } else {
        reason = args[1]
      }

      const embed = new Discord.MessageEmbed()
      .setTitle(`${user.username} was banned!`)
      .setDescription(`${user.username} was banned by ${message.author.username} for: ${reason}`)
      .setColor("#f0db4f")
      .setFooter("Ban Command")
      .setTimestamp()

      message.channel.send(embed)
      message.guild.members.ban(user)
  }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your command has few issues in it.

The first being that it does not allow banning users with command if the user is mentioned, it only allows banning by user ID. To fix that simply do:

const user = message.mentions.members.first() || await client.users.fetch(args[0])

You should also add check if the user is found, so right after you declare value for user

const user = message.mentions.members.first() || await client.users.fetch(args[0])
if(!user) return message.reply(`No user found`);

Now if you allow banning both mentions and user IDs there might be a different user value. So I recommend editing your embed aswell to something like:

const embed = new Discord.MessageEmbed()
      .setTitle(`${user.user.username} was banned!`)
      .setDescription(`${user.user.username} was banned by ${message.author.username} for: ${reason}`)
      .setColor("#f0db4f")
      .setFooter("Ban Command")
      .setTimestamp()

This should fix majority of your issues, I recommend that if something is undefined in future or you come across any bugs in your code. Do some debugging by sending messages to console console.log(variable) or console.log("This works?")

about 4 years ago · Juan Pablo Isaza Report

0

if you are using discord.js v12 you can do what the other answer said and get the user by mention message.mentions.members.first() but if you are using v13 that wont work anymore

the reason its giving that error is because you need to fetch the user by their id alone, so you can do this client.users.fetch(args[0].replace('<@!', '').replace('>', '')) to remove the <@! and > (mention prefix) from it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!