昵称包含 "x.." 的用户解禁

Unban users if their nickname contains "x.."

如果用户名包含 xx、已删除等,我不太确定如何让我的机器人取消对所有人的封禁

例如,如果用户的帐户 banned/deleted 不和谐,机器人将取消封禁他们以清除封禁日志,因为它包含“已删除的用户”。

我正在提供我现有的基于 ID 的解禁命令。

/**
 * JSDOC
 * @param {Discord.Client} client
 * @param {Discord.Message} message
 * @param {String} args
 */
module.exports.run = async (client, message, args) => {
if (!message.member.hasPermission('BAN_MEMBERS')) return message.channel.send('You are not allowed to unban members!');
    if (!message.guild.me.hasPermission('BAN_MEMBERS')) return message.channel.send('I am not allowed to unban members!');
    if (!args[0]) return message.reply('Please provide a user id to unban!', { allowedMentions: { repliedUser: false } });
    const toUnBan = client.users.cache.get(args[0].match(/[1234567890]{18}/igm)[0]) || await client.users.fetch(args[0], true, true);
    if (!toUnBan) return message.reply('You didnt provide a valid user!', { allowedMentions: { repliedUser: false } });
    try {
        (await message.guild.fetchBan(toUnBan));
    }
    catch (err) {
        return message.reply('The user isnt banned!', { allowedMentions: { repliedUser: false } });
    }
    message.guild.members.unban(toUnBan);
    
  • 解禁某个用户名的用户,需要先获取所有的bans,然后用用户名过滤,再解禁。
(await message.guild.bans.fetch())
.filter(ban => ban.username.toLowerCase().includes("deleted"))
.forEach(async(ban) => {
   await message.guild.bans.remove(ban.id).catch(e => console.log(e));
   console.log(`Unbanned ${ban.tag}`);
});