mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-06-08 07:59:29 +00:00
Added Warn and Ban Commands, Added Logging, and Much More
This commit is contained in:
parent
d89de72e08
commit
86adac3f08
33 changed files with 2200 additions and 204 deletions
85
src/commands/moderation/warn.ts
Normal file
85
src/commands/moderation/warn.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import {
|
||||
CommandInteraction,
|
||||
PermissionsBitField,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandOptionsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import { updateMemberModerationHistory } from '../../db/db.js';
|
||||
import logAction from '../../util/logging/logAction.js';
|
||||
|
||||
interface Command {
|
||||
data: SlashCommandOptionsOnlyBuilder;
|
||||
execute: (interaction: CommandInteraction) => Promise<void>;
|
||||
}
|
||||
|
||||
const command: Command = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('warn')
|
||||
.setDescription('Warn a member')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('member')
|
||||
.setDescription('The member to warn')
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('reason')
|
||||
.setDescription('The reason for the warning')
|
||||
.setRequired(true),
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
const moderator = await interaction.guild?.members.fetch(
|
||||
interaction.user.id,
|
||||
);
|
||||
const member = await interaction.guild?.members.fetch(
|
||||
interaction.options.get('member')!.value as unknown as string,
|
||||
);
|
||||
const reason = interaction.options.get('reason')
|
||||
?.value as unknown as string;
|
||||
|
||||
if (
|
||||
!interaction.memberPermissions?.has(
|
||||
PermissionsBitField.Flags.ModerateMembers,
|
||||
) ||
|
||||
moderator!.roles.highest.position <= member!.roles.highest.position
|
||||
) {
|
||||
await interaction.reply({
|
||||
content: 'You do not have permission to warn this member.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await updateMemberModerationHistory({
|
||||
discordId: member!.user.id,
|
||||
moderatorDiscordId: interaction.user.id,
|
||||
action: 'warning',
|
||||
reason: reason,
|
||||
duration: '',
|
||||
});
|
||||
await member!.user.send(
|
||||
`You have been warned in **${interaction?.guild?.name}**. Reason: **${reason}**.`,
|
||||
);
|
||||
await interaction.reply(
|
||||
`<@${member!.user.id}> has been warned. Reason: ${reason}`,
|
||||
);
|
||||
await logAction({
|
||||
guild: interaction.guild!,
|
||||
action: 'warn',
|
||||
target: member!,
|
||||
moderator: moderator!,
|
||||
reason: reason,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({
|
||||
content: 'There was an error trying to warn the member.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default command;
|
Loading…
Add table
Add a link
Reference in a new issue