mirror of
https://github.com/sern-handler/awesome-plugins
synced 2026-06-06 01:16:51 +00:00
refactor(permCheck): cleaned up code (#14)
Co-authored-by: EvolutionX <evolutionx9777@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* @author: @NeoYaBoi
|
||||
* @version: 1.0.0
|
||||
* @version: 1.0.1
|
||||
* @description: This is perm check, it allows users to parse the permission you want and let the plugin do the rest. (check user for that perm).
|
||||
* @license: Null
|
||||
* @example:
|
||||
@@ -9,7 +9,7 @@
|
||||
* import { permCheck } from "../plugins/permCheck"; //(change if need be)
|
||||
* import { sernModule, CommandType } from "@sern/handler";
|
||||
* export default commandModule({
|
||||
* plugins: [ permCheck('permission', 'Response Here') ],
|
||||
* plugins: [ permCheck('permission', 'No permission response') ],
|
||||
* execute: (ctx) => {
|
||||
* //your code here
|
||||
* }
|
||||
@@ -17,7 +17,7 @@
|
||||
* ```
|
||||
*/
|
||||
|
||||
import { PermissionResolvable, type GuildMember } from "discord.js";
|
||||
import { type GuildMember, PermissionResolvable } from "discord.js";
|
||||
import { CommandType, EventPlugin, PluginType } from "@sern/handler";
|
||||
export function permCheck(
|
||||
perm: PermissionResolvable,
|
||||
@@ -28,21 +28,16 @@ export function permCheck(
|
||||
description: "Checks for specified perm",
|
||||
async execute(event, controller) {
|
||||
const [ctx] = event;
|
||||
if (ctx.guild == null) {
|
||||
if (ctx.guild === null) {
|
||||
ctx.reply("This command cannot be used here");
|
||||
console.warn(
|
||||
"A command stopped because we couldn't check there permissions (was used in dms)"
|
||||
); //delete this line if you dont was to be notified when a command is used outside of a guild/server
|
||||
"PermCheck > A command stopped because we couldn't check a users permissions (was used in dms)"
|
||||
); //delete this line if you dont want to be notified when a command is used outside of a guild/server
|
||||
return controller.stop();
|
||||
}
|
||||
if (!(ctx.member! as GuildMember).permissions.has(perm)) {
|
||||
try {
|
||||
await ctx.reply(response);
|
||||
return controller.stop();
|
||||
} catch {
|
||||
ctx.reply("You do not have the required permissions");
|
||||
return controller.stop();
|
||||
}
|
||||
await ctx.reply(response);
|
||||
return controller.stop();
|
||||
}
|
||||
return controller.next();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user