AeThex-Bot-Master/aethex-bot/commands/warn.js
sirpiglr ca07d17417 Add new commands and improve bot functionality
Introduce several new slash commands including ban, kick, timeout, and userinfo. Enhance existing commands like config and rank with new features and configurations. Add new listeners for welcome and goodbye messages. Implement XP tracking for user leveling and integrate it with role rewards. Update documentation to reflect these changes.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 1be8d824-5029-4875-bed8-0bd1d810892d
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/SQxsvtx
Replit-Helium-Checkpoint-Created: true
2025-12-08 04:09:56 +00:00

90 lines
2.7 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('warn')
.setDescription('Warn a user')
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
.addUserOption(option =>
option.setName('user')
.setDescription('User to warn')
.setRequired(true)
)
.addStringOption(option =>
option.setName('reason')
.setDescription('Reason for warning')
.setRequired(true)
.setMaxLength(500)
),
async execute(interaction, supabase, client) {
const target = interaction.options.getUser('user');
const reason = interaction.options.getString('reason');
const moderator = interaction.user;
if (target.id === interaction.user.id) {
return interaction.reply({ content: 'You cannot warn yourself.', ephemeral: true });
}
if (target.bot) {
return interaction.reply({ content: 'You cannot warn bots.', ephemeral: true });
}
let warningCount = 1;
if (supabase) {
try {
await supabase.from('warnings').insert({
guild_id: interaction.guildId,
user_id: target.id,
user_tag: target.tag,
moderator_id: moderator.id,
moderator_tag: moderator.tag,
reason: reason,
});
const { count } = await supabase
.from('warnings')
.select('*', { count: 'exact', head: true })
.eq('guild_id', interaction.guildId)
.eq('user_id', target.id);
warningCount = count || 1;
} catch (e) {
console.warn('Failed to save warning:', e.message);
}
}
const embed = new EmbedBuilder()
.setColor(0xfbbf24)
.setTitle('User Warned')
.setThumbnail(target.displayAvatarURL())
.addFields(
{ name: 'User', value: `${target.tag} (${target.id})`, inline: true },
{ name: 'Moderator', value: moderator.tag, inline: true },
{ name: 'Warning #', value: `${warningCount}`, inline: true },
{ name: 'Reason', value: reason }
)
.setTimestamp();
await interaction.reply({ embeds: [embed] });
try {
await target.send({
embeds: [
new EmbedBuilder()
.setColor(0xfbbf24)
.setTitle(`Warning in ${interaction.guild.name}`)
.setDescription(`You have been warned by a moderator.`)
.addFields(
{ name: 'Reason', value: reason },
{ name: 'Warning #', value: `${warningCount}` }
)
.setTimestamp()
]
});
} catch (e) {
await interaction.followUp({ content: 'Could not DM user about the warning.', ephemeral: true });
}
},
};