Files
awesome-plugins/TypeScript/permCheck.ts
Jacob Nguyen a6d50c18b7 refactor: simpler plugins (#68)
* feat!: update ownerOnly

* feat!: update permCheck

* feat!: update publish

* feat!: update serverOnly

* feat!: update nsfwOnly

* feat!: update requirePermission

* feat!: update dmOnly

* feat!: update cooldown

* feat!: update confirmation

* feat!: update channelType

* feat!: update buttonConfirmation

* feat: addAssertFields (#67)

feat: add assertFields
2023-01-27 12:10:49 -06:00

41 lines
1.3 KiB
TypeScript

// @ts-nocheck
/**
* 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).
*
* @author @Benzo-Fury [<@762918086349029386>]
* @version 1.0.1
* @example
* ```ts
* import { permCheck } from "../plugins/permCheck";
* import { commandModule } from "@sern/handler";
* export default commandModule({
* plugins: [ permCheck('permission', 'No permission response') ],
* execute: (ctx) => {
* //your code here
* }
* })
* ```
*/
import type { GuildMember, PermissionResolvable } from "discord.js";
import {CommandControlPlugin, CommandType, controller } from "@sern/handler";
export function permCheck(
perm: PermissionResolvable,
response: string
) {
return CommandControlPlugin<CommandType.Both>(async (ctx, args) => {
if (ctx.guild === null) {
await ctx.reply("This command cannot be used here");
console.warn(
"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)) {
await ctx.reply(response);
return controller.stop();
}
return controller.next();
})
}