forked from Ryheff24/Massdiscordunban
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (47 loc) · 1.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { Client } = require("discord.js"); // V13 Now :]
const { token } = require("./config.json");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const rest = new REST({ version: "9" }).setToken(token);
const { Permissions } = require("discord.js");
const client = new Client({
intents: ["GUILDS", "GUILD_BANS", "GUILD_MESSAGE_TYPING"]
});
client.once("ready", () => {
console.log("Bot is online! Use /unban-all to unban all users.");
console.log("Your Bot invite link: " + client.generateInvite({ scopes: ['bot', 'applications.commands'], permissions: [Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.BAN_MEMBERS, Permissions.FLAGS.KICK_MEMBERS]}));
});
client.on("interactionCreate", async interaction => {
await interaction.deferReply();
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === "unban-all") {
if (interaction.member.permissions.has("BAN_MEMBERS")) {
try {
const bans = await rest.get(Routes.guildBans(interaction.guild.id));
//console.log(bans);
console.log(bans[0]);
const banNumbers = bans.length;
await interaction.editReply(
`Found ${banNumbers} bans in ${interaction.guild.name}`
);
for (const v of bans) {
await interaction.editReply(
`Unbanning user: ${v.user.username}#${v.user.discriminator}`
);
// console.log(v);
await interaction.guild.members.unban(v.user.id);
}
await interaction.editReply(`Unbanned all ${banNumbers} users`);
} catch (e) {
await interaction.editReply(`There was some unexpected error:\n\n${e}`);
}
} else {
await interaction.editReply(
"You do not have enough permissions for this command."
);
console.log("You do not have enough permissions for this command.");
}
}
});
client.login(token);