1+ import logging
12import typing
23import uuid
34
78from ..error import IncorrectFormat , IncorrectType
89from ..model import ButtonStyle , ComponentType
910
11+ logger = logging .getLogger ("discord_slash" )
12+
1013
1114def create_actionrow (* components : dict ) -> dict :
1215 """
@@ -128,6 +131,13 @@ def create_button(
128131 if not label and not emoji :
129132 raise IncorrectFormat ("You must have at least a label or emoji on a button." )
130133
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+
131141 emoji = emoji_to_dict (emoji )
132142
133143 data = {
@@ -166,6 +176,12 @@ def create_select_option(
166176
167177 if not len (label ) or len (label ) > 25 :
168178 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+ )
169185 if not len (value ) or len (value ) > 100 :
170186 raise IncorrectFormat ("Value length should be between 1 and 100." )
171187 if description is not None and len (description ) > 50 :
@@ -182,10 +198,10 @@ def create_select_option(
182198
183199def create_select (
184200 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 ,
189205):
190206 """
191207 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(
285301 message_ids = list (get_messages_ids (messages )) if messages else None
286302 custom_ids = list (get_components_ids (components )) if components else None
287303
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+
288312 def _check (ctx : ComponentContext ):
289313 if check and not check (ctx ):
290314 return False
0 commit comments