Skip to content

Commit f656b3e

Browse files
committed
feat: support for command permissions v2
1 parent d169067 commit f656b3e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: src/handlers/MessageCommandHandler.ts

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export async function MessageCommandHandler(
152152
}
153153

154154
if (!command.type.includes(CommandType.MESSAGE)) return;
155+
if (!message.guild && command.dmPermission === false) return;
155156

156157
if (command.cooldown) {
157158
const cooldown = Handlers.cooldownHandler(

Diff for: src/lib/structures/Command.ts

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Commands } from '../managers/CommandManager';
66
import { Locale, LocaleString } from '../util/common';
77
import { Logger } from '../util/logger/Logger';
88
import { commandAndOptionNameRegexp } from '../util/regexes';
9+
import type { PermissionResolvable, Permissions } from 'discord.js';
910

1011
export enum CommandType {
1112
/**
@@ -37,6 +38,8 @@ export interface CommandOptions {
3738
description?: string;
3839
descriptionLocalizations?: Record<LocaleString, string>;
3940
type: Array<CommandType | keyof typeof CommandType>;
41+
defaultMemberPermissions?: PermissionResolvable;
42+
dmPermission?: boolean;
4043
arguments?: Array<Argument | ArgumentOptions>;
4144
inhibitors?: CommandInhibitors;
4245
guildId?: string;
@@ -84,6 +87,8 @@ const validationSchema = z
8487
)
8588
.array()
8689
.nonempty(),
90+
defaultMemberPermissions: z.any().optional(),
91+
dmPermission: z.boolean().optional(),
8792
arguments: z.any().array().optional(),
8893
inhibitors: z.any().array().optional(),
8994
guildId: z.string().optional(),
@@ -109,6 +114,8 @@ export class Command {
109114
public description?: string;
110115
public descriptionLocalizations?: Record<LocaleString, string>;
111116
public type: Array<CommandType | keyof typeof CommandType>;
117+
public defaultMemberPermissions?: PermissionResolvable;
118+
public dmPermission?: boolean;
112119
public arguments?: Array<Argument>;
113120
public inhibitors: CommandInhibitors;
114121
public guildId?: string;
@@ -136,6 +143,11 @@ export class Command {
136143
options.descriptionLocalizations ||
137144
Command.defaults?.descriptionLocalizations;
138145
this.type = options.type || Command.defaults?.type;
146+
this.defaultMemberPermissions =
147+
options.defaultMemberPermissions ||
148+
Command.defaults?.defaultMemberPermissions;
149+
this.dmPermission =
150+
options.dmPermission || Command.defaults?.dmPermission;
139151
this.arguments = options.arguments?.map(argument => {
140152
if (argument instanceof Argument) return argument;
141153
else return new Argument(argument);
@@ -218,6 +230,8 @@ export class Command {
218230
name_localizations: this.nameLocalizations,
219231
description: this.description,
220232
description_localizations: this.descriptionLocalizations,
233+
dm_permission: this.dmPermission,
234+
default_member_permissions: this.defaultMemberPermissions,
221235
options: this.arguments?.map(argument => argument.toJSON()),
222236
type: type,
223237
};

0 commit comments

Comments
 (0)