File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -46,9 +46,11 @@ async def on_socket_response(self, res):
4646 for _type in InteractionEventType :
4747 if _type .value == res ["d" ]["data" ]["component_type" ]:
4848 self .bot .dispatch (f"raw_{ _type .name } " , res ["d" ])
49+ self .bot .dispatch (f"raw_interaction" , res ["d" ])
4950
5051 interaction = self ._get_interaction (res )
5152 self .bot .dispatch (_type .name , interaction )
53+ self .bot .dispatch ("interaction" , interaction )
5254 if self ._components_callback .get (interaction .custom_id ):
5355 callback_info = self ._components_callback [interaction .custom_id ]
5456 if callback_info ["uses" ] == 0 :
Original file line number Diff line number Diff line change @@ -46,4 +46,31 @@ async def select(ctx):
4646 await interaction .send (content = f"{ interaction .values [0 ]} selected!" )
4747
4848
49+ @bot .command ()
50+ async def interaction (ctx ):
51+ await ctx .send (
52+ "Buttons and Selects!" ,
53+ components = [
54+ Select (
55+ placeholder = "Select something!" ,
56+ options = [
57+ SelectOption (label = "a" , value = "a" ),
58+ SelectOption (label = "b" , value = "b" ),
59+ ],
60+ custom_id = "select1" ,
61+ ),
62+ Button (label = "Button" , custom_id = "button1" ),
63+ ],
64+ )
65+
66+ interaction = await bot .wait_for (
67+ "interaction" , check = lambda inter : inter .custom_id in ["select1" , "button1" ]
68+ )
69+
70+ if isinstance (interaction .component , Button ):
71+ await interaction .respond (content = "Button clicked!" )
72+ else :
73+ await interaction .respond (content = f"{ interaction .values [0 ]} selected!" )
74+
75+
4976bot .run ("your token" )
Original file line number Diff line number Diff line change @@ -47,4 +47,33 @@ async def on_select_option(interaction):
4747 await interaction .respond (content = f"{ interaction .values [0 ]} selected!" )
4848
4949
50+ @bot .command ()
51+ async def interaction (ctx ):
52+ await ctx .send (
53+ "Buttons and Selects!" ,
54+ components = [
55+ Select (
56+ placeholder = "Select something!" ,
57+ options = [
58+ SelectOption (label = "a" , value = "a" ),
59+ SelectOption (label = "b" , value = "b" ),
60+ ],
61+ custom_id = "select1" ,
62+ ),
63+ Button (label = "Button" , custom_id = "button1" ),
64+ ],
65+ )
66+
67+
68+ @bot .event
69+ async def on_interaction (interaction ):
70+ if interaction .custom_id not in ["select1" , "button1" ]:
71+ return
72+
73+ if isinstance (interaction .component , Button ):
74+ await interaction .respond (content = "Button clicked!" )
75+ else :
76+ await interaction .respond (content = f"{ interaction .values [0 ]} selected!" )
77+
78+
5079bot .run ("your token" )
You can’t perform that action at this time.
0 commit comments