-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunlock.js
102 lines (90 loc) · 3.13 KB
/
unlock.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const {
Client,
Interaction,
PermissionFlagsBits,
EmbedBuilder,
} = require("discord.js");
module.exports = {
/**
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageChannels)) {
return await interaction.reply({
content: "❌ You don't have permission to use this command.",
ephemeral: true
});
}
const targetChannel = interaction.options.getChannel("channel") || interaction.channel;
const targetRole = interaction.options.getRole("role");
const reason = interaction.options.getString("reason") || "N/A";
if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.ManageChannels)) {
return await interaction.reply({
content: "❌ I need the **Manage Channels** permission to execute this command!",
ephemeral: true
});
}
if (!targetRole) {
return await interaction.reply({
content: "❌ You must specify a role to unlock.",
ephemeral: true
});
}
try {
const currentPermissions = targetChannel.permissionOverwrites.cache.get(targetRole.id);
if (currentPermissions && !currentPermissions.deny.has(PermissionFlagsBits.SendMessages)) {
return await interaction.reply({
content: `🔓 The role <@&${targetRole.id}> is already unlocked in <#${targetChannel.id}>.`,
ephemeral: true
});
}
await targetChannel.permissionOverwrites.edit(targetRole.id, {
SendMessages: true
});
const confirmationEmbed = new EmbedBuilder()
.setColor("#4ea554")
.setTitle("Channel Unlocked")
.setDescription(`<#${targetChannel.id}> has been unlocked for <@&${targetRole.id}>.`)
.addFields({ name: "Reason", value: reason })
.setTimestamp()
.setFooter({ text: `Unlocked by ${interaction.user.tag}` });
await interaction.reply({ embeds: [confirmationEmbed] });
const unlockNoticeEmbed = new EmbedBuilder()
.setColor("#4ea554")
.setTitle("🔓 Channel Unlocked")
.setDescription(`This channel has been unlocked.`)
.addFields({ name: "Reason", value: reason })
.setTimestamp();
await targetChannel.send({ embeds: [unlockNoticeEmbed] });
} catch (error) {
console.error("Error unlocking the channel:", error);
await interaction.reply({
content: "❌ Failed to unlock the channel. Make sure I have the correct permissions.",
ephemeral: true
});
}
},
name: "unlock",
description: "Unlocks a channel by restoring send message permissions for a specific role.",
options: [
{
name: "channel",
description: "The channel to unlock (defaults to the current one).",
type: 7,
required: true,
},
{
name: "role",
description: "The role to unlock (restores send message permissions).",
type: 8,
required: true,
},
{
name: "reason",
description: "Reason for unlocking the channel.",
type: 3,
required: false,
},
],
};