I'm kinda new to coding discord bots and I have a problem. I want to have a ban command that would ban the mentioned user in the command or the user that has an ID that was provided in the command. For example: &ban @User#0001 would ban User#0001 but if the command looks like this: &ban 123456789123456789 (let's say that's the ID of User#0001) it would still ban User#0001 (as it is the user's ID).
I have this code, it works if I mention the user, but it doesn't work if I enter the ID.
const Discord = require('discord.js');
module.exports = {
name: 'testban',
description: "Executer will ban the mentioned user",
execute(message, args){
if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Invalid Permissions")
let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
if (!User) return message.channel.send("Invalid User")
if (User.hasPermission("BAN_MEMBERS")) return message.reply("Can't ban that one, he also can ban")
let banReason = args.join(" ").slice(22);
if (!banReason) {
banReason = "None"
}
console.log(`USER = ${User}`)
User.ban({reason: banReason})
var UserID = User.id
console.log(`USER ID = ${UserID}`)
}
}
The error I get when entering the ID is this:
message.guild.members.get is not a function
How could I make it ban the person even if I only provide the ID?