11import { ApplicationCommandOptionType } from "discord.js" ;
2- import { AI_NAME , DEFAULT_MODE } from "../config.js" ;
2+ import { AI_NAME , DEFAULT_MODE , DEFAULT_MODEL , GPT_MODELS , MODEL_SURNAMES } from "../config.js" ;
33import setBotActivity from "../utils/setBotActivity.js" ;
44
55async function ready ( client ) {
6- console . log ( `${ AI_NAME } is online!` ) ;
7- client . currentMode = DEFAULT_MODE ;
8- setBotActivity ( client , client . currentMode ) ;
6+ console . log ( `${ AI_NAME } is online!` ) ;
7+ client . currentMode = DEFAULT_MODE ;
8+ client . currentModel = DEFAULT_MODEL ;
9+ setBotActivity ( client , client . currentMode , client . currentModel ) ;
910
10- // First, delete existing commands to avoid conflicts
11- try {
12- await client . application ?. commands . fetch ( ) ;
13- console . log ( "Successfully fetched application commands" ) ;
14- } catch ( error ) {
15- console . error ( "Error fetching commands:" , error ) ;
16- }
11+ // Set up the commands
12+ const commands = [
13+ {
14+ name : "gpt-mode" ,
15+ description : "Switch between GPT text and voice modes" ,
16+ options : [
17+ {
18+ type : ApplicationCommandOptionType . String ,
19+ name : "mode" ,
20+ description : "Select the mode" ,
21+ required : true ,
22+ choices : [
23+ { name : "Text" , value : "text" } ,
24+ { name : "Voice" , value : "voice" }
25+ ]
26+ } ,
27+ ] ,
28+ } ,
29+ {
30+ name : "gpt-model" ,
31+ description : "Choose the GPT model to use" ,
32+ options : [
33+ {
34+ type : ApplicationCommandOptionType . String ,
35+ name : "model" ,
36+ description : "Select the model" ,
37+ required : true ,
38+ choices : [
39+ { name : MODEL_SURNAMES [ GPT_MODELS . GPT4O ] , value : GPT_MODELS . GPT4O } ,
40+ { name : MODEL_SURNAMES [ GPT_MODELS . GPT41 ] , value : GPT_MODELS . GPT41 } ,
41+ { name : MODEL_SURNAMES [ GPT_MODELS . O3 ] , value : GPT_MODELS . O3 }
42+ ]
43+ } ,
44+ ] ,
45+ } ,
46+ {
47+ name : "image" ,
48+ description : "Generate an image with GPT-Image-1 model" ,
49+ options : [
50+ {
51+ type : ApplicationCommandOptionType . String ,
52+ name : "description" ,
53+ description : "Description of the image to generate" ,
54+ required : true ,
55+ } ,
56+ ] ,
57+ } ,
58+ {
59+ name : "image-edit" ,
60+ description : "Edit an image with GPT-Image-1 model" ,
61+ options : [
62+ {
63+ type : ApplicationCommandOptionType . String ,
64+ name : "description" ,
65+ description : "Description of the edit to make" ,
66+ required : true ,
67+ } ,
68+ {
69+ type : ApplicationCommandOptionType . Attachment ,
70+ name : "image" ,
71+ description : "The image to edit" ,
72+ required : true ,
73+ } ,
74+ ] ,
75+ } ,
76+ ] ;
1777
18- // Set up the commands
19- const commands = [
20- {
21- name : "gpt-voice" ,
22- description : "Switch to GPT-VOICE mode" ,
23- } ,
24- {
25- name : "gpt-text" ,
26- description : "Switch to GPT-TEXT mode" ,
27- } ,
28- {
29- name : "image" ,
30- description : "Generate an image with GPT-Image-1 model" ,
31- options : [
32- {
33- type : ApplicationCommandOptionType . String ,
34- name : "description" ,
35- description : "Description of the image to generate" ,
36- required : true ,
37- } ,
38- ] ,
39- } ,
40- {
41- name : "image-edit" ,
42- description : "Edit an image with GPT-Image-1 model" ,
43- options : [
44- {
45- type : ApplicationCommandOptionType . String ,
46- name : "description" ,
47- description : "Description of the edit to make" ,
48- required : true ,
49- } ,
50- {
51- type : ApplicationCommandOptionType . Attachment ,
52- name : "image" ,
53- description : "The image to edit" ,
54- required : true ,
55- } ,
56- ] ,
57- } ,
58- ] ;
59-
60- try {
61- // Clear the existing commands first
62- await client . application . commands . set ( [ ] ) ;
63- console . log ( "Cleared existing commands" ) ;
64-
65- // Then register the new ones
66- await client . application . commands . set ( commands ) ;
67- console . log ( "Commands registered successfully" ) ;
68- } catch ( error ) {
69- console . error ( "Error registering commands:" , error ) ;
70- }
78+ try {
79+ // First fetch the existing commands
80+ const existingCommands = await client . application ?. commands . fetch ( ) ;
81+ console . log ( "Successfully fetched application commands" ) ;
82+
83+ // Clear the existing commands
84+ await client . application . commands . set ( [ ] ) ;
85+ console . log ( "Cleared existing commands" ) ;
86+
87+ // Register the new commands and wait for it to complete
88+ const newCommands = await client . application . commands . set ( commands ) ;
89+ console . log ( `Commands registered successfully (${ newCommands . size } commands)` ) ;
90+
91+ return true ; // Signal successful completion
92+ } catch ( error ) {
93+ console . error ( "Error registering commands:" , error ) ;
94+ return false ; // Signal failure
95+ }
7196}
7297
73- export default ready ;
98+ export default ready ;
0 commit comments