mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Leave all blacklisted guilds when blacklist is used
This commit is contained in:
@@ -147,8 +147,11 @@ client.on('message', async msg => {
|
||||
|
||||
client.on('guildCreate', async guild => {
|
||||
if (client.blacklist.guild.includes(guild.id) || client.blacklist.user.includes(guild.ownerID)) {
|
||||
guild.leave();
|
||||
return;
|
||||
try {
|
||||
await guild.leave();
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (guild.systemChannel && guild.systemChannel.permissionsFor(client.user).has('SEND_MESSAGES')) {
|
||||
try {
|
||||
|
||||
@@ -33,6 +33,30 @@ module.exports = class BlacklistCommand extends Command {
|
||||
if (this.client.blacklist[type].includes(target)) return msg.say(`🔨 \`${target}\` is already blacklisted.`);
|
||||
this.client.blacklist[type].push(target);
|
||||
this.client.exportBlacklist();
|
||||
if (type === 'guild') {
|
||||
try {
|
||||
const guild = await this.client.guilds.fetch(target, false);
|
||||
await guild.leave();
|
||||
} catch {
|
||||
await msg.say('🔨 Failed to leave guild.');
|
||||
}
|
||||
}
|
||||
if (type === 'user') {
|
||||
let guildsLeft = 0;
|
||||
const failedToLeave = [];
|
||||
for (const guild of this.client.guilds.cache.values()) {
|
||||
if (guild.ownerID === target) {
|
||||
try {
|
||||
await guild.leave();
|
||||
guildsLeft++;
|
||||
} catch {
|
||||
failedToLeave.push(guild.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
const formatFailed = failedToLeave.length ? failedToLeave.map(id => `\`${id}\``).join(', ') : '_None_';
|
||||
await msg.say(`🔨 Left ${guildsLeft} guilds owner by this user. Failed to leave: ${formatFailed}`);
|
||||
}
|
||||
return msg.say(`🔨 Blacklisted ${type} \`${target}\`.`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user