aboutsummaryrefslogtreecommitdiff
path: root/lib/arguments/permission.ts
blob: 4d09e9cd0410c38cbc28df7bd4430e6f998484da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
import type { BotArgumentTypeCaster } from '#lib';
import { PermissionFlagsBits, type PermissionsString } from 'discord.js';

export const permission: BotArgumentTypeCaster<PermissionsString | null> = (_, phrase) => {
	if (!phrase) return null;
	phrase = phrase.toUpperCase().replace(/ /g, '_');
	if (!(phrase in PermissionFlagsBits)) {
		return null;
	} else {
		return phrase as PermissionsString;
	}
};