mirror of
https://github.com/sern-handler/awesome-plugins
synced 2026-06-06 01:16:51 +00:00
chore: update JavaScript plugins Co-authored-by: EvolutionX-10 <EvolutionX-10@users.noreply.github.com>
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
// @ts-nocheck
|
|
|
|
/**
|
|
* This plugin checks if a channel is the specified type
|
|
*
|
|
* @author @Benzo-Fury [<@762918086349029386>]
|
|
* @version 1.0.0
|
|
* @example
|
|
* ```ts
|
|
* import { channelType } from "../plugins/channelType";
|
|
* import { ChannelType } from "discord.js"
|
|
* import { commandModule } from "@sern/handler";
|
|
* export default commandModule({
|
|
* plugins: [ channelType([ChannelType.GuildText], 'This cannot be used here') ],
|
|
* execute: (ctx) => {
|
|
* //your code here
|
|
* }
|
|
* })
|
|
* ```
|
|
*/
|
|
import { ChannelType } from "discord.js";
|
|
import { CommandControlPlugin, controller } from "@sern/handler";
|
|
export function channelType(channelType, onFail) {
|
|
return CommandControlPlugin(async (ctx, args) => {
|
|
let channel = ctx.channel?.type; //for some reason the dm channel type was returning undefined at some points
|
|
|
|
if (channel === undefined) {
|
|
channel = ChannelType.DM;
|
|
}
|
|
|
|
if (channelType.includes(channel)) {
|
|
return controller.next();
|
|
}
|
|
|
|
if (onFail) {
|
|
await ctx.reply(onFail);
|
|
}
|
|
|
|
return controller.stop();
|
|
});
|
|
}
|