-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SlashCommandBuilder, PermissionsBitField, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; | ||
|
||
export const data = new SlashCommandBuilder() | ||
.setName('clear') | ||
.setDescription('Clear messages') | ||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) | ||
.addStringOption(option => option.setName('amount').setDescription('The number of messages to clear (up to 99)').setRequired(true)) | ||
|
||
export async function execute(interaction) { | ||
const { options } = interaction; | ||
|
||
const amount = options.getString('amount'); | ||
const user = interaction.user.username; | ||
|
||
if (!interaction.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) { | ||
return interaction.reply({ content: 'No perms', ephemeral: true }); | ||
} | ||
|
||
if (isNaN(amount) || parseInt(amount) < 1 || parseInt(amount) > 99) { | ||
return interaction.reply({ content: 'Please provide a valid number between 1 and 99.', ephemeral: true }); | ||
} | ||
|
||
await interaction.deferReply({ ephemeral: true }); | ||
|
||
const deletedSize = await deleteMessages(interaction.channel, parseInt(amount), user); | ||
|
||
const clearEmbed = new EmbedBuilder() | ||
.setAuthor({ name: 'Clear' }) | ||
.setColor('#333333') | ||
.setTitle(`Clear used in ${interaction.channel}`) | ||
.setThumbnail(interaction.client.user.avatarURL()) | ||
.setFooter({ text: `Clear` }) | ||
.setTimestamp() | ||
|
||
console.log(deletedSize); | ||
return interaction.followUp({ embeds: [clearEmbed], ephemeral: true }); | ||
} | ||
|
||
async function deleteMessages(channel, amount) { | ||
const total = amount; | ||
|
||
// true arg forces the bot to delete msgs that older then 14 days | ||
const count = await channel.bulkDelete(total, true); | ||
console.log(count.size); | ||
console.log(count); | ||
|
||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; | ||
|
||
export const data = new SlashCommandBuilder() | ||
.setName("permissions") | ||
.setDescription("Displays permissions of given user.") | ||
.addUserOption(option => option.setName("user").setDescription("The user to get permissions for").setRequired(false)) | ||
|
||
export async function execute(interaction) { | ||
if (!interaction.isChatInputCommand()) return; | ||
|
||
const { options } = interaction; | ||
|
||
const member = options.getMember("user") || interaction.member; | ||
const user = options.getUser("user") || interaction.user; | ||
|
||
if (!member) return interaction.reply({ content: "Member **could not** be found!", ephemeral: true, }); | ||
|
||
let permissionFlags = Object.keys(PermissionFlagsBits); | ||
|
||
let output = `**Permissions for** **${member}:** \n\`\`\``; | ||
for (let i = 0; i < permissionFlags.length; i++) { | ||
let permissionName = permissionFlags[i]; | ||
let hasPermission = member.permissions.has(permissionName); | ||
output += `${permissionName} ${hasPermission ? "true" : "false"}\n`; | ||
} | ||
output += `\`\`\``; | ||
|
||
const PermsEmbed = new EmbedBuilder() | ||
.setTitle('Permissions') | ||
.setDescription(`> **${user.tag}** permissions in **${interaction.guild.name}** \n\n${output}`) | ||
.setColor('#555555') | ||
.setThumbnail(user.avatarURL()) | ||
.setFooter({ text: `${user.tag} permissions` }) | ||
.setTimestamp(); | ||
|
||
return interaction.reply({ embeds: [PermsEmbed] }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters