MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / checkBotPermissions

Function checkBotPermissions

src/utils/permissionGuard.js:55–105  ·  view source on GitHub ↗
(
  interaction,
  requiredPermissions,
  channel = null
)

Source from the content-addressed store, hash-verified

53}
54
55export async function checkBotPermissions(
56 interaction,
57 requiredPermissions,
58 channel = null
59) {
60 const targetChannel = channel || interaction.channel;
61
62 if (!targetChannel || !targetChannel.guild) {
63 await replyUserError(interaction, {
64 type: ErrorTypes.UNKNOWN,
65 message: 'Could not determine channel.',
66 context: { source: 'permissionGuard.checkBotPermissions' }
67 });
68 return false;
69 }
70
71 const botMember = targetChannel.guild.members.me;
72 if (!botMember) {
73 await replyUserError(interaction, {
74 type: ErrorTypes.UNKNOWN,
75 message: 'Could not find bot member in this guild.',
76 context: { source: 'permissionGuard.checkBotPermissions' }
77 });
78 return false;
79 }
80
81 const permissions = targetChannel.permissionsFor(botMember);
82 const missingPerms = [];
83
84 const permArray = Array.isArray(requiredPermissions) ? requiredPermissions : [requiredPermissions];
85 for (const perm of permArray) {
86 if (!permissions.has(perm)) {
87 missingPerms.push(perm);
88 }
89 }
90
91 if (missingPerms.length > 0) {
92 await replyUserError(interaction, {
93 type: ErrorTypes.PERMISSION,
94 message: `I need the following permissions in ${targetChannel}: ${missingPerms.join(', ')}`,
95 context: { source: 'permissionGuard.checkBotPermissions', subtype: 'bot_permission' }
96 });
97
98 logger.warn(
99 `[BOT_PERMISSION_DENIED] Bot missing permissions [${missingPerms.join(', ')}] in channel ${targetChannel.id}`
100 );
101 return false;
102 }
103
104 return true;
105}
106
107function hashUserId(userId) {
108

Callers

nothing calls this directly

Calls 1

replyUserErrorFunction · 0.90

Tested by

no test coverage detected