mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
Permission check utils
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { GuildMember } from 'discord.js';
|
||||
import { BaseGuildTextChannel, BaseGuildVoiceChannel, Guild, GuildChannelResolvable, GuildMember, VoiceBasedChannel } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
import { COMMON_EMBEDS } from '../discord/Settings';
|
||||
import { sendHybridInteractionMessageResponse } from './DiscordMessage';
|
||||
@@ -19,8 +19,58 @@ export async function checkMemberPermissions({
|
||||
|
||||
if (!hasPermissions && data && locale)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [COMMON_EMBEDS.NO_PERMISSION(data, locale, permissions)]
|
||||
embeds: [COMMON_EMBEDS.MEMBER_NO_PERMISSION(data, locale, permissions)]
|
||||
});
|
||||
|
||||
return hasPermissions;
|
||||
}
|
||||
|
||||
export async function checkBotPermissions({
|
||||
guild,
|
||||
permissions,
|
||||
data,
|
||||
locale
|
||||
}: {
|
||||
guild: Guild;
|
||||
permissions: bigint[];
|
||||
data?: HybridInteractionMessage;
|
||||
locale?: I18n;
|
||||
}): Promise<boolean> {
|
||||
const member = guild.members.me;
|
||||
if(!member) return false;
|
||||
|
||||
const hasPermissions = member.permissions.has(permissions);
|
||||
|
||||
if (!hasPermissions && data && locale)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [COMMON_EMBEDS.BOT_NO_PERMISSION(data, locale, permissions)]
|
||||
});
|
||||
|
||||
return hasPermissions;
|
||||
}
|
||||
|
||||
export async function checkBotPermissionsInChannel({
|
||||
guild,
|
||||
channel,
|
||||
permissions,
|
||||
data,
|
||||
locale
|
||||
}: {
|
||||
guild: Guild;
|
||||
channel: GuildChannelResolvable;
|
||||
permissions: bigint[];
|
||||
data?: HybridInteractionMessage;
|
||||
locale?: I18n;
|
||||
}): Promise<boolean> {
|
||||
const member = guild.members.me;
|
||||
if(!member) return false;
|
||||
|
||||
const hasPermissions = member.permissionsIn(channel).has(permissions);
|
||||
|
||||
if (!hasPermissions && data && locale)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [COMMON_EMBEDS.BOT_NO_PERMISSION(data, locale, permissions)]
|
||||
});
|
||||
|
||||
return hasPermissions;
|
||||
}
|
||||
Reference in New Issue
Block a user