@@ -14,7 +14,6 @@ import (
1414 "github.com/disgoorg/disgo"
1515 "github.com/disgoorg/disgo/bot"
1616 "github.com/disgoorg/disgo/discord"
17- "github.com/disgoorg/disgo/events"
1817 "github.com/disgoorg/disgo/handler"
1918)
2019
3635 Required : false ,
3736 },
3837 },
38+ IntegrationTypes : []discord.ApplicationIntegrationType {
39+ discord .ApplicationIntegrationTypeGuildInstall ,
40+ discord .ApplicationIntegrationTypeUserInstall ,
41+ },
42+ Contexts : []discord.InteractionContextType {
43+ discord .InteractionContextTypeGuild ,
44+ discord .InteractionContextTypeBotDM ,
45+ discord .InteractionContextTypePrivateChannel ,
46+ },
3947 },
4048 }
4149)
@@ -45,9 +53,14 @@ func main() {
4553 slog .Info ("disgo version" , slog .String ("version" , disgo .Version ))
4654 slog .SetLogLoggerLevel (slog .LevelDebug )
4755
56+ r := handler .New ()
57+ r .SlashCommand ("/test" , onTest )
58+ r .SlashCommand ("/modal" , onModal )
59+ r .Modal ("/modal" , onModalSubmit )
60+
4861 client , err := disgo .New (token ,
4962 bot .WithDefaultGateway (),
50- bot .WithEventListenerFunc ( onCommand ),
63+ bot .WithEventListeners ( r ),
5164 )
5265 if err != nil {
5366 slog .Error ("error while building bot" , slog .Any ("err" , err ))
@@ -70,39 +83,54 @@ func main() {
7083 <- s
7184}
7285
73- func onCommand (e * events.ApplicationCommandInteractionCreate ) {
74- switch data := e .Data .(type ) {
75- case discord.SlashCommandInteractionData :
76- flags := discord .MessageFlagIsComponentsV2
77- if ephemeral , ok := data .OptBool ("ephemeral" ); ! ok || ephemeral {
78- flags = flags .Add (discord .MessageFlagEphemeral )
79- }
80- if err := e .CreateMessage (discord.MessageCreate {
81- Flags : flags ,
82- Components : []discord.LayoutComponent {
83- discord .NewContainer (
84- discord .NewSection (
85- discord .NewTextDisplay ("**Name: [Seeing Red](https://open.spotify.com/track/65qBr6ToDUjTD1RiE1H4Gl)**" ),
86- discord .NewTextDisplay ("**Artist: [Architects](https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv)**" ),
87- discord .NewTextDisplay ("**Album: [The Sky, The Earth & All Between](https://open.spotify.com/album/2W82VyyIFAXigJEiLm5TT1)**" ),
88- ).WithAccessory (discord .NewThumbnail ("attachment://thumbnail.png" )),
89- discord .NewTextDisplay ("`0:08`/`3:40`" ),
90- discord .NewTextDisplay ("[🔘▬▬▬▬▬▬▬▬▬]" ),
91- discord .NewSmallSeparator (),
92- discord .NewActionRow (
93- discord .NewPrimaryButton ("" , "/player/previous" ).WithEmoji (discord.ComponentEmoji {Name : "⏮" }),
94- discord .NewPrimaryButton ("" , "/player/pause_play" ).WithEmoji (discord.ComponentEmoji {Name : "⏯" }),
95- discord .NewPrimaryButton ("" , "/player/next" ).WithEmoji (discord.ComponentEmoji {Name : "⏭" }),
96- discord .NewDangerButton ("" , "/player/stop" ).WithEmoji (discord.ComponentEmoji {Name : "⏹" }),
97- discord .NewPrimaryButton ("" , "/player/like" ).WithEmoji (discord.ComponentEmoji {Name : "❤️" }),
98- ),
99- ).WithAccentColor (0x5c5fea ),
100- },
101- Files : []* discord.File {
102- discord .NewFile ("thumbnail.png" , "" , bytes .NewReader (thumbnail )),
103- },
104- }); err != nil {
105- slog .Error ("error while sending message" , slog .Any ("err" , err ))
106- }
86+ func onTest (data discord.SlashCommandInteractionData , e * handler.CommandEvent ) error {
87+ flags := discord .MessageFlagIsComponentsV2
88+ if ephemeral , ok := data .OptBool ("ephemeral" ); ! ok || ephemeral {
89+ flags = flags .Add (discord .MessageFlagEphemeral )
10790 }
91+
92+ return e .CreateMessage (discord.MessageCreate {
93+ Flags : flags ,
94+ Components : []discord.LayoutComponent {
95+ discord .NewContainer (
96+ discord .NewSection (
97+ discord .NewTextDisplay ("**Name: [Seeing Red](https://open.spotify.com/track/65qBr6ToDUjTD1RiE1H4Gl)**" ),
98+ discord .NewTextDisplay ("**Artist: [Architects](https://open.spotify.com/artist/3ZztVuWxHzNpl0THurTFCv)**" ),
99+ discord .NewTextDisplay ("**Album: [The Sky, The Earth & All Between](https://open.spotify.com/album/2W82VyyIFAXigJEiLm5TT1)**" ),
100+ ).WithAccessory (discord .NewThumbnail ("attachment://thumbnail.png" )),
101+ discord .NewTextDisplay ("`0:08`/`3:40`" ),
102+ discord .NewTextDisplay ("[🔘▬▬▬▬▬▬▬▬▬]" ),
103+ discord .NewSmallSeparator (),
104+ discord .NewActionRow (
105+ discord .NewPrimaryButton ("" , "/player/previous" ).WithEmoji (discord.ComponentEmoji {Name : "⏮" }),
106+ discord .NewPrimaryButton ("" , "/player/pause_play" ).WithEmoji (discord.ComponentEmoji {Name : "⏯" }),
107+ discord .NewPrimaryButton ("" , "/player/next" ).WithEmoji (discord.ComponentEmoji {Name : "⏭" }),
108+ discord .NewDangerButton ("" , "/player/stop" ).WithEmoji (discord.ComponentEmoji {Name : "⏹" }),
109+ discord .NewPrimaryButton ("" , "/player/like" ).WithEmoji (discord.ComponentEmoji {Name : "❤️" }),
110+ ),
111+ ).WithAccentColor (0x5c5fea ),
112+ },
113+ Files : []* discord.File {
114+ discord .NewFile ("thumbnail.png" , "" , bytes .NewReader (thumbnail )),
115+ },
116+ })
117+ }
118+
119+ func onModal (_ discord.SlashCommandInteractionData , e * handler.CommandEvent ) error {
120+ return e .Modal (discord.ModalCreate {
121+ CustomID : "/modal" ,
122+ Title : "Test Modal" ,
123+ Components : []discord.LayoutComponent {
124+ discord .NewTextDisplay ("This is a modal" ),
125+ discord .NewLabel ("Test Input" , discord .NewShortTextInput ("test_input" )),
126+ discord .NewLabel ("Test Select" , discord .NewUserSelectMenu ("test_user" , "Select a user" )),
127+ },
128+ })
129+ }
130+
131+ func onModalSubmit (e * handler.ModalEvent ) error {
132+ return e .CreateMessage (discord.MessageCreate {
133+ Content : "You submitted the modal!" ,
134+ Flags : discord .MessageFlagEphemeral ,
135+ })
108136}
0 commit comments