File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ import discord
2
+
3
+ # Channel selects (dropdowns) are a new type of select menu/dropdown Discord has added so users can select channels from a dropdown.
4
+
5
+ # Defines a simple View that allows the user to use the Select menu.
6
+ # In this view, we define the channel_select with `discord.ui.channel_select`
7
+ # Using the decorator automatically sets `select_type` to `discord.ComponentType.channel_select`.
8
+ class DropdownView (discord .ui .View ):
9
+ @discord .ui .channel_select (
10
+ placeholder = "Select channels..." , min_values = 1 , max_values = 3
11
+ ) # Users can select a maximum of 3 channels in the dropdown
12
+ async def channel_select_dropdown (self , select , interaction ):
13
+ await interaction .response .send_message (
14
+ f"You selected the following channels:"
15
+ + f", " .join (f"{ channel .mention } " for channel in select .values )
16
+ )
17
+
18
+
19
+ bot = discord .Bot (debug_guilds = [...])
20
+
21
+
22
+ @bot .slash_command ()
23
+ async def channel_select (ctx : discord .ApplicationContext ):
24
+ """Sends a message with our dropdown that contains a channel select."""
25
+
26
+ # Create the view containing our dropdown
27
+ view = DropdownView ()
28
+
29
+ # Sending a message containing our View
30
+ await ctx .respond ("Select channels:" , view = view )
31
+
32
+
33
+ @bot .event
34
+ async def on_ready ():
35
+ print (f"Logged in as { bot .user } (ID: { bot .user .id } )" )
36
+ print ("------" )
37
+
38
+
39
+ bot .run ("TOKEN" )
Original file line number Diff line number Diff line change
1
+ import discord
2
+
3
+ # Role selects (dropdowns) are a new type of select menu/dropdown Discord has added so people can select server roles from a dropdown.
4
+
5
+ # Defines a simple View that allows the user to use the Select menu.
6
+ # In this view, we define the role_select with `discord.ui.role_select`
7
+ # Using the decorator automatically sets `select_type` to `discord.ComponentType.role_select`.
8
+ class DropdownView (discord .ui .View ):
9
+ @discord .ui .role_select (
10
+ placeholder = "Select roles..." , min_values = 1 , max_values = 3
11
+ ) # Users can select a maximum of 3 roles in the dropdown
12
+ async def role_select_dropdown (self , select , interaction ):
13
+ await interaction .response .send_message (
14
+ f"You selected the following roles:"
15
+ + f", " .join (f"{ role .mention } " for role in select .values )
16
+ )
17
+
18
+
19
+ bot = discord .Bot (debug_guilds = [...])
20
+
21
+
22
+ @bot .slash_command ()
23
+ async def role_select (ctx : discord .ApplicationContext ):
24
+ """Sends a message with our dropdown that contains a role select."""
25
+
26
+ # Create the view containing our dropdown
27
+ view = DropdownView ()
28
+
29
+ # Sending a message containing our View
30
+ await ctx .respond ("Select roles:" , view = view )
31
+
32
+
33
+ @bot .event
34
+ async def on_ready ():
35
+ print (f"Logged in as { bot .user } (ID: { bot .user .id } )" )
36
+ print ("------" )
37
+
38
+
39
+ bot .run ("TOKEN" )
You can’t perform that action at this time.
0 commit comments