Okay so you are just getting first user mention from message mentions, you are not checking if there is any user or not
const { ReactionCollector, User } = require("discord.js");
module.exports = {
name: 'unban',
description: "Odbanuje ?lena.",
async execute(message, args, Discord, client, chalk){
await message.channel.messages.fetch({limit: 1}).then(messages =>{
message.channel.bulkDelete(messages);
});
const channelId = client.channels.cache.get('802649418087530537');
const author = message.author;
const userName = message.mentions.users.first();
if (!userName) return message.channel.send("please mention a user");
let userId = message.guild.members.cache.get(userName.id);
if(!message.member.permissions.has("BAN_MEMBERS")){
message.reply('Nemá? pot?ebné permisse!')
.then(msg => {
msg.delete({ timeout: 5000 })
});
console.log(chalk.red('[ERROR] (./commands/unban/) Missing "BAN_MEMBERS" permission'));
return;
} else if(!args[1]){
message.reply('`!unban <?len> <d?vod>`')
.then(msg => {
msg.delete({ timeout: 5000 })
});
console.log(chalk.red('[ERROR] (./commands/unban/) Missing args[1]'));
return;
}
const banList = await message.guild.fetchBans();
const bannedUser = banList.find(user => user.id === userId);
if(bannedUser){
let reason = args.slice(1).join(" ");
const botId = '799652033509457940';
const banEmbed = new Discord.MessageEmbed()
.setColor('#2ca819')
.setTitle('Unban')
.addFields(
{name:'?len:', value:`${userId}`},
{name:'Udělil:', value:`${author}`},
{name:'D?vod:', value:`${reason}`},
)
.setTimestamp()
channelId.send(banEmbed)
await userId.unban()
console.log(chalk.green(`[INFO] (./commands/unban/) User "${userId.user.username}" was unbanned"`));
}else{
message.reply('Tohoto ?lena nem??u najít.')
.then(msg => {
msg.delete({ timeout: 5000 })
});
console.log(chalk.red(`[ERROR] (./commands/unban/) Can not find target`));
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…