@@ -3,14 +3,16 @@ import {
33 ButtonInteraction ,
44 ButtonStyle ,
55 MessageFlags ,
6- ModalBuilder ,
6+ ModalBuilder , REST , Routes ,
77 TextInputBuilder ,
88 TextInputStyle
99} from "discord.js" ;
1010import { convertToEmojiPng } from "../../../helper/emojis.js" ;
1111import { ExtendedClient } from "../../../types/client.js" ;
1212import { protectedCommands } from "../../../main/data.js" ;
1313import { database } from "../../../main/database.js" ;
14+ import { Logger } from "../../../main/logger.js" ;
15+ import { Config } from "../../../main/config.js" ;
1416
1517export default {
1618 id : "commands-manager-toggle" ,
@@ -49,8 +51,31 @@ export default {
4951 for ( const command of commands . values ( ) ) {
5052 if (
5153 command . name != data . CustomName &&
52- command . guildId == interaction . guild ?. id
54+ command . guildId == interaction . guild ?. id && ! data . IsEnabled
5355 ) {
56+
57+ const restClient = new REST ( { version : "10" } ) . setToken ( Config . Bot . DiscordBotToken ) ;
58+
59+ const json = client . commands . get ( data . CodeName ) . data . toJSON ( ) ;
60+
61+ json . name = data . CustomName ;
62+ json . description = data . Description ;
63+ json . default_member_permissions = data . Permissions ;
64+
65+ const currentCommands = await restClient . get (
66+ Routes . applicationGuildCommands ( Config . Bot . DiscordApplicationId , interaction . guild . id )
67+ ) as any [ ]
68+
69+ const newCommands = [ ...currentCommands , json ] ;
70+
71+ await restClient . put (
72+ Routes . applicationGuildCommands ( Config . Bot . DiscordApplicationId , interaction . guild . id ) ,
73+ {
74+ body : newCommands ,
75+ }
76+ ) ;
77+
78+
5479 await database . buildInCommands . update ( {
5580 where : {
5681 UUID : interaction . customId . split ( ":" ) [ 1 ]
@@ -59,17 +84,6 @@ export default {
5984 IsEnabled : true
6085 }
6186 } )
62- await interaction . guild . commands . create (
63- {
64- name : data . CustomName ,
65- description : client . commands . get ( data . CodeName ) . data . description ,
66- contexts : client . commands . get ( data . CodeName ) . data . contexts ,
67- options : client . commands . get ( data . CodeName ) . data . options as any ,
68- default_member_permissions : client . commands . get ( data . CodeName ) . data . default_member_permissions ,
69- integrationTypes : client . commands . get ( data . CodeName ) . data . integration_types ,
70- dmPermission : false
71- }
72- )
7387
7488 return await interaction . reply ( {
7589 flags : MessageFlags . Ephemeral ,
@@ -80,8 +94,7 @@ export default {
8094 command . name == data . CustomName &&
8195 command . guildId == interaction . guild ?. id
8296 ) {
83-
84- await interaction . guild . commands . delete ( command . id )
97+ await command . delete ( )
8598 await database . buildInCommands . update ( {
8699 where : {
87100 UUID : interaction . customId . split ( ":" ) [ 1 ]
@@ -97,6 +110,7 @@ export default {
97110 }
98111 }
99112 } catch ( error ) {
113+ Logger . error ( error ) ;
100114 return await interaction . reply ( {
101115 flags : MessageFlags . Ephemeral ,
102116 content : `## ${ await convertToEmojiPng ( "error" , client . user . id ) } Can't remove this command from the Guild!`
0 commit comments