1
+ import logging
1
2
import typing
2
3
import uuid
3
4
7
8
from ..error import IncorrectFormat , IncorrectType
8
9
from ..model import ButtonStyle , ComponentType
9
10
11
+ logger = logging .getLogger ("discord_slash" )
12
+
10
13
11
14
def create_actionrow (* components : dict ) -> dict :
12
15
"""
@@ -128,6 +131,13 @@ def create_button(
128
131
if not label and not emoji :
129
132
raise IncorrectFormat ("You must have at least a label or emoji on a button." )
130
133
134
+ if custom_id is not None and not isinstance (custom_id , str ):
135
+ custom_id = str (custom_id )
136
+ logger .warning (
137
+ "Custom_id has been automatically converted to a string. Please use strings in future\n "
138
+ "Note: Discord will always return custom_id as a string"
139
+ )
140
+
131
141
emoji = emoji_to_dict (emoji )
132
142
133
143
data = {
@@ -166,6 +176,12 @@ def create_select_option(
166
176
167
177
if not len (label ) or len (label ) > 25 :
168
178
raise IncorrectFormat ("Label length should be between 1 and 25." )
179
+ if not isinstance (value , str ):
180
+ value = str (value )
181
+ logger .warning (
182
+ "Value has been automatically converted to a string. Please use strings in future\n "
183
+ "Note: Discord will always return value as a string"
184
+ )
169
185
if not len (value ) or len (value ) > 100 :
170
186
raise IncorrectFormat ("Value length should be between 1 and 100." )
171
187
if description is not None and len (description ) > 50 :
@@ -182,10 +198,10 @@ def create_select_option(
182
198
183
199
def create_select (
184
200
options : typing .List [dict ],
185
- custom_id = None ,
186
- placeholder = None ,
187
- min_values = None ,
188
- max_values = None ,
201
+ custom_id : str = None ,
202
+ placeholder : typing . Optional [ str ] = None ,
203
+ min_values : typing . Optional [ int ] = None ,
204
+ max_values : typing . Optional [ int ] = None ,
189
205
):
190
206
"""
191
207
Creates a select (dropdown) component for use with the ``components`` field. Must be inside an ActionRow to be used (see :meth:`create_actionrow`).
@@ -285,6 +301,14 @@ async def wait_for_component(
285
301
message_ids = list (get_messages_ids (messages )) if messages else None
286
302
custom_ids = list (get_components_ids (components )) if components else None
287
303
304
+ # automatically convert improper custom_ids
305
+ if not all (isinstance (x , str ) for x in custom_ids ):
306
+ custom_ids = [str (i ) for i in custom_ids ]
307
+ logger .warning (
308
+ "Custom_ids have been automatically converted to a list of strings. Please use lists of strings in future.\n "
309
+ "Note: Discord will always return custom_ids as strings"
310
+ )
311
+
288
312
def _check (ctx : ComponentContext ):
289
313
if check and not check (ctx ):
290
314
return False
0 commit comments