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

Method banUser

src/services/moderationService.js:135–208  ·  view source on GitHub ↗
({
    guild,
    user,
    moderator,
    reason = 'No reason provided',
    deleteDays = 0
  })

Source from the content-addressed store, hash-verified

133 }
134
135 static async banUser({
136 guild,
137 user,
138 moderator,
139 reason = 'No reason provided',
140 deleteDays = 0
141 }) {
142 try {
143 if (!guild || !user || !moderator) {
144 throw new TitanBotError(
145 'Missing required parameters',
146 ErrorTypes.VALIDATION,
147 'Guild, user, and moderator are required'
148 );
149 }
150
151 let targetMember = null;
152 try {
153 targetMember = await guild.members.fetch(user.id).catch(() => null);
154 } catch (err) {
155 logger.debug('Target not in guild, proceeding with ban');
156 }
157
158 if (targetMember) {
159 this.assertModerationHierarchy(moderator, targetMember, 'ban');
160 } else {
161
162 const isOwner = guild.ownerId === moderator.id;
163 const hasHighPerms = moderator.permissions.has([
164 PermissionFlagsBits.ManageGuild,
165 PermissionFlagsBits.Administrator
166 ]);
167
168 if (!isOwner && !hasHighPerms) {
169 throw new TitanBotError(
170 'You do not have sufficient permissions to ban users who are not in the server.',
171 ErrorTypes.PERMISSION,
172 'You need "Manage Server" or "Administrator" permissions to ban users not currently in the guild.'
173 );
174 }
175 }
176
177 await guild.members.ban(user.id, { reason });
178
179 const caseId = await logModerationAction({
180 client: guild.client,
181 guild,
182 event: {
183 action: 'Member Banned',
184 target: `${user.tag} (${user.id})`,
185 executor: `${moderator.user.tag} (${moderator.id})`,
186 reason,
187 metadata: {
188 userId: user.id,
189 moderatorId: moderator.id,
190 permanent: true,
191 deleteDays
192 }

Callers 1

executeFunction · 0.80

Calls 2

logModerationActionFunction · 0.90

Tested by

no test coverage detected