-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLockCommand.ts
More file actions
53 lines (45 loc) · 1.65 KB
/
Copy pathLockCommand.ts
File metadata and controls
53 lines (45 loc) · 1.65 KB
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
import { PermissionFlagsBits, TextChannel } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';
export default class LockCommand extends Command {
constructor() {
super({
name: 'lock',
description: 'Lock a channel',
requiredPermissions: [PermissionFlagsBits.ManageChannels],
checkFlags: CommandCheckFlags.Guild,
args: [
new Argument({
name: 'channel',
description: 'The channel to lock',
type: 'channel',
required: false,
}),
],
});
}
public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.guild!;
const channel = context.args.channel
? guild.channels.cache.get(context.args.channel as string)
: (context.interaction?.channel ?? context.message?.channel);
if (!channel || !channel.isTextBased()) {
return await context.reply({
embeds: [Embeds.error('Channel not found or not text-based.')],
});
}
const textChannel = channel as TextChannel;
const everyoneRole = guild.roles.everyone;
const isLocked = textChannel.permissionOverwrites.cache
.get(everyoneRole.id)
?.deny.has(PermissionFlagsBits.SendMessages);
await textChannel.permissionOverwrites.edit(everyoneRole, {
SendMessages: isLocked ? null : false,
});
await context.reply({
embeds: [Embeds.success(`Channel ${isLocked ? 'unlocked' : 'locked'}!`)],
});
}
}