mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Added DM channel purge
This commit is contained in:
parent
180acb318c
commit
1e673a3969
2 changed files with 45 additions and 24 deletions
|
@ -284,30 +284,6 @@ export default new NamedCommand({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
purge: new NamedCommand({
|
|
||||||
description: "Purges the bot's own messages.",
|
|
||||||
permission: PERMISSIONS.BOT_SUPPORT,
|
|
||||||
channelType: CHANNEL_TYPE.GUILD,
|
|
||||||
async run({send, message, channel, guild, client}) {
|
|
||||||
// It's probably better to go through the bot's own messages instead of calling bulkDelete which requires MANAGE_MESSAGES.
|
|
||||||
if (guild!.me?.hasPermission(Permissions.FLAGS.MANAGE_MESSAGES)) {
|
|
||||||
message.delete();
|
|
||||||
const msgs = await channel.messages.fetch({
|
|
||||||
limit: 100
|
|
||||||
});
|
|
||||||
const travMessages = msgs.filter((m) => m.author.id === client.user?.id);
|
|
||||||
|
|
||||||
await send(`Found ${travMessages.size} messages to delete.`).then((m) =>
|
|
||||||
m.delete({
|
|
||||||
timeout: 5000
|
|
||||||
})
|
|
||||||
);
|
|
||||||
await (channel as TextChannel).bulkDelete(travMessages);
|
|
||||||
} else {
|
|
||||||
send("This command must be executed in a guild where I have the `MANAGE_MESSAGES` permission.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
clear: new NamedCommand({
|
clear: new NamedCommand({
|
||||||
description: "Clears a given amount of messages.",
|
description: "Clears a given amount of messages.",
|
||||||
usage: "<amount>",
|
usage: "<amount>",
|
||||||
|
|
45
src/commands/utility/purge.ts
Normal file
45
src/commands/utility/purge.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import {NamedCommand, getPermissionLevel, getPermissionName, hasPermission} from "onion-lasers";
|
||||||
|
import {DMChannel, Permissions} from "discord.js";
|
||||||
|
|
||||||
|
export default new NamedCommand({
|
||||||
|
description:
|
||||||
|
"Purges the bot's messages in either a guild channel (requiring the BOT_SUPPORT permission level) or a DM channel (no permission required). Limited to the last 100 messages.",
|
||||||
|
async run({send, message, channel, guild, client, author, member}) {
|
||||||
|
if (channel instanceof DMChannel) {
|
||||||
|
const messages = await channel.messages.fetch({
|
||||||
|
limit: 100
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const message of messages.values()) {
|
||||||
|
if (message.author.id === client.user!.id) {
|
||||||
|
message.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (hasPermission(author, member, PERMISSIONS.BOT_SUPPORT)) {
|
||||||
|
if (guild!.me?.hasPermission(Permissions.FLAGS.MANAGE_MESSAGES)) message.delete();
|
||||||
|
|
||||||
|
const messages = await channel.messages.fetch({
|
||||||
|
limit: 100
|
||||||
|
});
|
||||||
|
const travMessages = messages.filter((msg) => msg.author.id === client.user!.id);
|
||||||
|
|
||||||
|
send(`Found ${travMessages.size} messages to delete.`).then((msg) => msg.delete({timeout: 5000}));
|
||||||
|
|
||||||
|
// It's better to go through the bot's own messages instead of calling bulkDelete which requires MANAGE_MESSAGES.
|
||||||
|
for (const message of messages.values()) {
|
||||||
|
if (message.author.id === client.user!.id) {
|
||||||
|
message.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const userPermLevel = getPermissionLevel(author, member);
|
||||||
|
send(
|
||||||
|
`You don't have access to this command! Your permission level is \`${getPermissionName(
|
||||||
|
userPermLevel
|
||||||
|
)}\` (${userPermLevel}), but this command requires a permission level of \`${getPermissionName(
|
||||||
|
PERMISSIONS.BOT_SUPPORT
|
||||||
|
)}\` (${PERMISSIONS.BOT_SUPPORT}).`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue