11import { ChatInputCommand } from '@/types'
2- import { ChatInputCommandInteraction , EmbedBuilder , SlashCommandBuilder } from 'discord.js'
2+ import {
3+ ChatInputCommandInteraction ,
4+ EmbedBuilder ,
5+ GuildMemberRoleManager ,
6+ SlashCommandBuilder ,
7+ } from 'discord.js'
8+ import process from 'node:process'
9+ import { PERMISSION_ERROR_TEXT } from '@/data'
10+ import { info } from '@/logging/logger'
311
412export const pmCommand : ChatInputCommand = {
513 data : new SlashCommandBuilder ( )
614 . setName ( 'pm' )
7- . setDescription ( 'Send a private message. ' )
15+ . setDescription ( 'Send a private message' )
816 . addStringOption ( ( option ) =>
917 option . setName ( 'id' ) . setDescription ( 'Discord User ID' ) . setRequired ( true ) ,
1018 )
19+ . addStringOption ( ( option ) =>
20+ option . setName ( 'reason' ) . setDescription ( 'Reason for sending a message' ) . setRequired ( true ) ,
21+ )
1122 . addStringOption ( ( option ) =>
1223 option . setName ( 'message' ) . setDescription ( 'Private message' ) . setRequired ( true ) ,
1324 )
1425 . addStringOption ( ( option ) =>
1526 option . setName ( 'title' ) . setDescription ( 'Embed title' ) . setRequired ( false ) ,
1627 ) as SlashCommandBuilder ,
1728 meta : {
18- name : 'reset ' ,
19- description : 'Reset user active role and message counter ' ,
29+ name : 'pm ' ,
30+ description : 'Send a private message' ,
2031 category : 'moderation' ,
2132 guildOnly : true ,
2233 } ,
2334 execute : async ( interaction : ChatInputCommandInteraction ) => {
24- if ( ! interaction . guild ) return
35+ if ( ! interaction . guild || ! interaction . member ) return
36+ if (
37+ ! ( interaction . member . roles as GuildMemberRoleManager ) . cache . has (
38+ process . env . DISCORD_MODERATOR_ROLE_ID ! ,
39+ )
40+ ) {
41+ await interaction . reply ( {
42+ content : PERMISSION_ERROR_TEXT ,
43+ flags : 'Ephemeral' ,
44+ } )
45+ return
46+ }
2547
2648 const id = interaction . options . getString ( 'id' , true )
49+ const reason = interaction . options . getString ( 'reason' , true )
2750 const message = interaction . options . getString ( 'message' , true )
2851 const title = interaction . options . getString ( 'title' , false )
2952 const member = await interaction . guild . members . fetch ( id )
@@ -34,5 +57,12 @@ export const pmCommand: ChatInputCommand = {
3457 . setDescription ( message )
3558
3659 await member . user . send ( { embeds : [ embed ] } )
60+ await interaction . reply ( {
61+ content : 'Private message has been successfully sent!' ,
62+ flags : 'Ephemeral' ,
63+ } )
64+ info (
65+ `:incoming_envelope: Moderator (\`${ interaction . user . username } \`, ID: ${ interaction . user . id } ) has sent a private message to a user ${ member . user } (\`${ member . user . username } \`, ID: ${ member . user . id } ), with a reason: ${ reason } .` ,
66+ )
3767 } ,
3868}
0 commit comments