diff --git a/discord/abc.py b/discord/abc.py index 3a40dbf4ea..e39629c904 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -44,7 +44,7 @@ from . import utils from .context_managers import Typing from .enums import ChannelType -from .errors import ClientException, InvalidArgument +from .errors import ClientException from .file import File, VoiceMessage from .flags import ChannelFlags, MessageFlags from .invite import Invite @@ -357,7 +357,7 @@ async def _move( reason: str | None, ) -> None: if position < 0: - raise InvalidArgument("Channel position cannot be less than 0.") + raise ValueError("Channel position cannot be less than 0.") http = self._state.http bucket = self._sorting_bucket @@ -460,7 +460,7 @@ async def _edit(self, options: dict[str, Any], reason: str | None) -> ChannelPay perms = [] for target, perm in overwrites.items(): if not isinstance(perm, PermissionOverwrite): - raise InvalidArgument(f"Expected PermissionOverwrite received {perm.__class__.__name__}") + raise TypeError(f"Expected PermissionOverwrite received {perm.__class__.__name__}") allow, deny = perm.pair() payload = { @@ -479,7 +479,7 @@ async def _edit(self, options: dict[str, Any], reason: str | None) -> ChannelPay pass else: if not isinstance(ch_type, ChannelType): - raise InvalidArgument("type field must be of type ChannelType") + raise TypeError("type field must be of type ChannelType") options["type"] = ch_type.value try: @@ -496,7 +496,7 @@ async def _edit(self, options: dict[str, Any], reason: str | None) -> ChannelPay elif default_reaction_emoji is None: pass else: - raise InvalidArgument("default_reaction_emoji must be of type: GuildEmoji | int | str | None") + raise TypeError("default_reaction_emoji must be of type: GuildEmoji | int | str | None") options["default_reaction_emoji"] = ( default_reaction_emoji._to_forum_reaction_payload() if default_reaction_emoji else None @@ -893,7 +893,7 @@ async def set_permissions(self, target, *, overwrite=MISSING, reason=None, **per Editing channel specific permissions failed. ~discord.NotFound The role or member being edited is not part of the guild. - ~discord.InvalidArgument + TypeError or ValueError The overwrite parameter invalid or the target type was not :class:`~discord.Role` or :class:`~discord.Member`. """ @@ -905,17 +905,17 @@ async def set_permissions(self, target, *, overwrite=MISSING, reason=None, **per elif isinstance(target, Role): perm_type = _Overwrites.ROLE else: - raise InvalidArgument("target parameter must be either Member or Role") + raise TypeError("target parameter must be either Member or Role") if overwrite is MISSING: if len(permissions) == 0: - raise InvalidArgument("No overwrite provided.") + raise ValueError("No overwrite provided.") try: overwrite = PermissionOverwrite(**permissions) except (ValueError, TypeError) as e: - raise InvalidArgument("Invalid permissions given to keyword arguments.") from e + raise ValueError("Invalid permissions given to keyword arguments.") from e elif len(permissions) > 0: - raise InvalidArgument("Cannot mix overwrite and keyword arguments.") + raise ValueError("Cannot mix overwrite and keyword arguments.") # TODO: wait for event @@ -925,7 +925,7 @@ async def set_permissions(self, target, *, overwrite=MISSING, reason=None, **per (allow, deny) = overwrite.pair() await http.edit_channel_permissions(self.id, target.id, allow.value, deny.value, perm_type, reason=reason) else: - raise InvalidArgument("Invalid overwrite type provided.") + raise ValueError("Invalid overwrite type provided.") async def _clone_impl( self: GCH, @@ -1074,7 +1074,7 @@ async def move(self, **kwargs) -> None: Raises ------ - InvalidArgument + ValueError An invalid position was given or a bad mix of arguments was passed. Forbidden You do not have permissions to move the channel. @@ -1089,7 +1089,7 @@ async def move(self, **kwargs) -> None: before, after = kwargs.get("before"), kwargs.get("after") offset = kwargs.get("offset", 0) if sum(bool(a) for a in (beginning, end, before, after)) > 1: - raise InvalidArgument("Only one of [before, after, end, beginning] can be used.") + raise ValueError("Only one of [before, after, end, beginning] can be used.") bucket = self._sorting_bucket parent_id = kwargs.get("category", MISSING) @@ -1124,7 +1124,7 @@ async def move(self, **kwargs) -> None: index = next((i + 1 for i, c in enumerate(channels) if c.id == after.id), None) if index is None: - raise InvalidArgument("Could not resolve appropriate move position") + raise ValueError("Could not resolve appropriate move position") channels.insert(max((index + offset), 0), self) payload = [] @@ -1481,7 +1481,7 @@ async def send( Sending the message failed. ~discord.Forbidden You do not have the proper permissions to send the message. - ~discord.InvalidArgument + TypeError or ValueError The ``files`` list is not of the appropriate size, you specified both ``file`` and ``files``, or you specified both ``embed`` and ``embeds``, @@ -1494,14 +1494,14 @@ async def send( content = str(content) if content is not None else None if embed is not None and embeds is not None: - raise InvalidArgument("cannot pass both embed and embeds parameter to send()") + raise ValueError("cannot pass both embed and embeds parameter to send()") if embed is not None: embed = embed.to_dict() elif embeds is not None: if len(embeds) > 10: - raise InvalidArgument("embeds parameter must be a list of up to 10 elements") + raise ValueError("embeds parameter must be a list of up to 10 elements") embeds = [embed.to_dict() for embed in embeds] flags = MessageFlags( @@ -1537,13 +1537,13 @@ async def send( "3.0", ) except AttributeError: - raise InvalidArgument( + raise ValueError( "reference parameter must be Message, MessageReference, or PartialMessage" ) from None if view: if not hasattr(view, "__discord_ui_view__"): - raise InvalidArgument(f"view parameter must be View not {view.__class__!r}") + raise TypeError(f"view parameter must be View not {view.__class__!r}") components = view.to_components() if view.is_components_v2(): @@ -1557,17 +1557,17 @@ async def send( poll = poll.to_dict() if file is not None and files is not None: - raise InvalidArgument("cannot pass both file and files parameter to send()") + raise ValueError("cannot pass both file and files parameter to send()") if file is not None: if not isinstance(file, File): - raise InvalidArgument("file parameter must be File") + raise TypeError("file parameter must be File") files = [file] elif files is not None: if len(files) > 10: - raise InvalidArgument("files parameter must be a list of up to 10 elements") + raise ValueError("files parameter must be a list of up to 10 elements") elif not all(isinstance(file, File) for file in files): - raise InvalidArgument("files parameter must be a list of File") + raise TypeError("files parameter must be a list of File") if files is not None: flags = flags + MessageFlags(is_voice_message=any(isinstance(f, VoiceMessage) for f in files)) diff --git a/discord/asset.py b/discord/asset.py index afdd47f3aa..66752d7335 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -32,7 +32,7 @@ import yarl from . import utils -from .errors import DiscordException, InvalidArgument +from .errors import DiscordException __all__ = ("Asset",) @@ -401,7 +401,7 @@ def replace( Raises ------ - InvalidArgument + TypeError or ValueError An invalid size or format was passed. """ url = yarl.URL(self._url) @@ -410,21 +410,21 @@ def replace( if format is not MISSING: if self._animated: if format not in VALID_ASSET_FORMATS: - raise InvalidArgument(f"format must be one of {VALID_ASSET_FORMATS}") + raise ValueError(f"format must be one of {VALID_ASSET_FORMATS}") url = url.with_path(f"{path}.{format}") elif static_format is MISSING: if format not in VALID_STATIC_FORMATS: - raise InvalidArgument(f"format must be one of {VALID_STATIC_FORMATS}") + raise ValueError(f"format must be one of {VALID_STATIC_FORMATS}") url = url.with_path(f"{path}.{format}") if static_format is not MISSING and not self._animated: if static_format not in VALID_STATIC_FORMATS: - raise InvalidArgument(f"static_format must be one of {VALID_STATIC_FORMATS}") + raise ValueError(f"static_format must be one of {VALID_STATIC_FORMATS}") url = url.with_path(f"{path}.{static_format}") if size is not MISSING: if not _valid_icon_size(size): - raise InvalidArgument("size must be a power of 2 between 16 and 4096") + raise ValueError("size must be a power of 2 between 16 and 4096") url = url.with_query(size=size) else: url = url.with_query(url.raw_query_string) @@ -447,11 +447,11 @@ def with_size(self, size: int, /) -> Asset: Raises ------ - InvalidArgument + TypeError or ValueError The asset had an invalid size. """ if not _valid_icon_size(size): - raise InvalidArgument("size must be a power of 2 between 16 and 4096") + raise ValueError("size must be a power of 2 between 16 and 4096") url = str(yarl.URL(self._url).with_query(size=size)) return Asset(state=self._state, url=url, key=self._key, animated=self._animated) @@ -471,15 +471,15 @@ def with_format(self, format: ValidAssetFormatTypes, /) -> Asset: Raises ------ - InvalidArgument + TypeError or ValueError The asset has an invalid format. """ if self._animated: if format not in VALID_ASSET_FORMATS: - raise InvalidArgument(f"format must be one of {VALID_ASSET_FORMATS}") + raise ValueError(f"format must be one of {VALID_ASSET_FORMATS}") elif format not in VALID_STATIC_FORMATS: - raise InvalidArgument(f"format must be one of {VALID_STATIC_FORMATS}") + raise ValueError(f"format must be one of {VALID_STATIC_FORMATS}") url = yarl.URL(self._url) path, _ = os.path.splitext(url.path) @@ -504,7 +504,7 @@ def with_static_format(self, format: ValidStaticFormatTypes, /) -> Asset: Raises ------ - InvalidArgument + TypeError or ValueError The asset had an invalid format. """ diff --git a/discord/channel.py b/discord/channel.py index fb8b196265..2b52b8eb6f 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -55,7 +55,7 @@ try_enum, ) from .enums import ThreadArchiveDuration as ThreadArchiveDurationEnum -from .errors import ClientException, InvalidArgument +from .errors import ClientException from .file import File from .flags import ChannelFlags, MessageFlags from .invite import Invite @@ -562,7 +562,7 @@ async def follow(self, *, destination: TextChannel, reason: str | None = None) - raise ClientException("The channel must be a news channel.") if not isinstance(destination, TextChannel): - raise InvalidArgument(f"Expected TextChannel received {destination.__class__.__name__}") + raise TypeError(f"Expected TextChannel received {destination.__class__.__name__}") from .webhook import Webhook # noqa: PLC0415 @@ -827,7 +827,7 @@ async def edit(self, *, reason=None, **options): Raises ------ - InvalidArgument + TypeError or ValueError If position is less than 0 or greater than the number of channels, or if the permission overwrite information is not in proper form. Forbidden @@ -1138,7 +1138,7 @@ async def edit(self, *, reason=None, **options): Raises ------ - InvalidArgument + TypeError or ValueError If position is less than 0 or greater than the number of channels, or if the permission overwrite information is not in proper form. Forbidden @@ -1245,14 +1245,14 @@ async def create_thread( message_content = str(content) if content is not None else None if embed is not None and embeds is not None: - raise InvalidArgument("cannot pass both embed and embeds parameter to create_thread()") + raise ValueError("cannot pass both embed and embeds parameter to create_thread()") if embed is not None: embed = embed.to_dict() elif embeds is not None: if len(embeds) > 10: - raise InvalidArgument("embeds parameter must be a list of up to 10 elements") + raise ValueError("embeds parameter must be a list of up to 10 elements") embeds = [embed.to_dict() for embed in embeds] if stickers is not None: @@ -1272,7 +1272,7 @@ async def create_thread( if view: if not hasattr(view, "__discord_ui_view__"): - raise InvalidArgument(f"view parameter must be View not {view.__class__!r}") + raise TypeError(f"view parameter must be View not {view.__class__!r}") components = view.to_components() if view.is_components_v2(): @@ -1286,17 +1286,17 @@ async def create_thread( applied_tags = [str(tag.id) for tag in applied_tags] if file is not None and files is not None: - raise InvalidArgument("cannot pass both file and files parameter to send()") + raise ValueError("cannot pass both file and files parameter to send()") if files is not None: if len(files) > 10: - raise InvalidArgument("files parameter must be a list of up to 10 elements") + raise ValueError("files parameter must be a list of up to 10 elements") elif not all(isinstance(file, File) for file in files): - raise InvalidArgument("files parameter must be a list of File") + raise TypeError("files parameter must be a list of File") if file is not None: if not isinstance(file, File): - raise InvalidArgument("file parameter must be File") + raise TypeError("file parameter must be File") files = [file] try: @@ -1499,7 +1499,7 @@ async def edit(self, *, reason=None, **options): Raises ------ - InvalidArgument + TypeError or ValueError If position is less than 0 or greater than the number of channels, or if the permission overwrite information is not in proper form. Forbidden @@ -2074,7 +2074,7 @@ async def edit(self, *, reason=None, **options): Raises ------ - InvalidArgument + TypeError or ValueError If the permission overwrite information is not in proper form. Forbidden You do not have permissions to edit the channel. @@ -2606,7 +2606,7 @@ async def create_instance( Raises ------ - InvalidArgument + TypeError or ValueError If the ``privacy_level`` parameter is not the proper type. Forbidden You do not have permissions to create a stage instance. @@ -2622,7 +2622,7 @@ async def create_instance( if privacy_level is not MISSING: if not isinstance(privacy_level, StagePrivacyLevel): - raise InvalidArgument("privacy_level field must be of type PrivacyLevel") + raise TypeError("privacy_level field must be of type PrivacyLevel") payload["privacy_level"] = privacy_level.value @@ -2725,7 +2725,7 @@ async def edit(self, *, reason=None, **options): Raises ------ - InvalidArgument + TypeError or ValueError If the permission overwrite information is not in proper form. Forbidden You do not have permissions to edit the channel. @@ -2870,7 +2870,7 @@ async def edit(self, *, reason=None, **options): Raises ------ - InvalidArgument + TypeError or ValueError If position is less than 0 or greater than the number of categories. Forbidden You do not have permissions to edit the category. diff --git a/discord/client.py b/discord/client.py index 225904bd50..baf0d7f55c 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1454,7 +1454,7 @@ async def change_presence( Raises ------ - :exc:`InvalidArgument` + TypeError or ValueError If the ``activity`` parameter is not the proper type. Example @@ -1659,7 +1659,7 @@ async def create_guild( ------ :exc:`HTTPException` Guild creation failed. - :exc:`InvalidArgument` + TypeError or ValueError Invalid icon image format given. Must be PNG or JPG. """ if icon is not MISSING: diff --git a/discord/commands/core.py b/discord/commands/core.py index 0351513601..7462c4d26a 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -59,7 +59,6 @@ ApplicationCommandInvokeError, CheckFailure, ClientException, - InvalidArgument, ValidationError, ) from ..member import Member @@ -240,9 +239,9 @@ def __init__(self, func: Callable, **kwargs) -> None: reference="https://discord.com/developers/docs/change-log#userinstallable-apps-preview", ) if contexts and guild_only: - raise InvalidArgument("cannot pass both 'contexts' and 'guild_only' to ApplicationCommand") + raise ValueError("cannot pass both 'contexts' and 'guild_only' to ApplicationCommand") if self.guild_ids and ((contexts is not None) or guild_only or integration_types): - raise InvalidArgument( + raise ValueError( "the 'contexts' and 'integration_types' parameters are not available for guild commands" ) @@ -1214,9 +1213,9 @@ def __init__( if guild_only is not MISSING: warn_deprecated("guild_only", "contexts", "2.6") if contexts and guild_only: - raise InvalidArgument("cannot pass both 'contexts' and 'guild_only' to ApplicationCommand") + raise ValueError("cannot pass both 'contexts' and 'guild_only' to ApplicationCommand") if self.guild_ids and ((contexts is not None) or guild_only or integration_types): - raise InvalidArgument( + raise ValueError( "the 'contexts' and 'integration_types' parameters are not available for guild commands" ) diff --git a/discord/errors.py b/discord/errors.py index d694180bc6..64c30791ad 100644 --- a/discord/errors.py +++ b/discord/errors.py @@ -50,7 +50,6 @@ "NotFound", "DiscordServerError", "InvalidData", - "InvalidArgument", "LoginFailure", "ConnectionClosed", "PrivilegedIntentsRequired", @@ -188,16 +187,6 @@ class InvalidData(ClientException): """ -class InvalidArgument(ClientException): - """Exception that's raised when an argument to a function - is invalid some way (e.g. wrong value or wrong type). - - This could be considered the parallel of ``ValueError`` and - ``TypeError`` except inherited from :exc:`ClientException` and thus - :exc:`DiscordException`. - """ - - class LoginFailure(ClientException): """Exception that's raised when the :meth:`Client.login` function fails to log you in from improper credentials or some other misc. diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py index f3c1a6866f..b434823ade 100644 --- a/discord/ext/pages/pagination.py +++ b/discord/ext/pages/pagination.py @@ -149,7 +149,7 @@ def __init__( **kwargs, ): if content is None and embeds is None and custom_view is None: - raise discord.InvalidArgument("A page must at least have content, embeds, or custom_view set.") + raise ValueError("A page must at least have content, embeds, or custom_view set.") self._content = content self._embeds = embeds or [] self._custom_view = custom_view diff --git a/discord/gateway.py b/discord/gateway.py index de25237c71..c314644050 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -42,7 +42,7 @@ from . import utils from .activity import BaseActivity from .enums import SpeakingState -from .errors import ConnectionClosed, InvalidArgument +from .errors import ConnectionClosed from .utils.private import from_json, to_json _log = logging.getLogger(__name__) @@ -662,7 +662,7 @@ async def send_heartbeat(self, data): async def change_presence(self, *, activity=None, status=None, since=0.0): if activity is not None: if not isinstance(activity, BaseActivity): - raise InvalidArgument("activity must derive from BaseActivity.") + raise TypeError("activity must derive from BaseActivity.") activity = [activity.to_dict()] else: activity = [] diff --git a/discord/guild.py b/discord/guild.py index f269e49c5f..a0a7880d12 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -66,7 +66,7 @@ VoiceRegion, try_enum, ) -from .errors import ClientException, InvalidArgument, InvalidData +from .errors import ClientException, InvalidData from .file import File from .flags import SystemChannelFlags from .incidents import IncidentsData @@ -1207,12 +1207,12 @@ def _create_channel( if overwrites is MISSING: overwrites = {} elif not isinstance(overwrites, dict): - raise InvalidArgument("overwrites parameter expects a dict.") + raise TypeError("overwrites parameter expects a dict.") perms = [] for target, perm in overwrites.items(): if not isinstance(perm, PermissionOverwrite): - raise InvalidArgument(f"Expected PermissionOverwrite received {perm.__class__.__name__}") + raise TypeError(f"Expected PermissionOverwrite received {perm.__class__.__name__}") allow, deny = perm.pair() payload = { @@ -1310,7 +1310,7 @@ async def create_text_channel( You do not have the proper permissions to create this channel. HTTPException Creating the channel failed. - InvalidArgument + TypeError or ValueError The permission overwrite information is not in proper form. Examples @@ -1437,7 +1437,7 @@ async def create_voice_channel( You do not have the proper permissions to create this channel. HTTPException Creating the channel failed. - InvalidArgument + TypeError or ValueError The permission overwrite information is not in proper form. """ options = {} @@ -1559,7 +1559,7 @@ async def create_stage_channel( You do not have the proper permissions to create this channel. HTTPException Creating the channel failed. - InvalidArgument + TypeError or ValueError The permission overwrite information is not in proper form. """ @@ -1696,7 +1696,7 @@ async def create_forum_channel( You do not have the proper permissions to create this channel. HTTPException Creating the channel failed. - InvalidArgument + TypeError or ValueError The argument is not in proper form. Examples @@ -1755,7 +1755,7 @@ async def create_forum_channel( elif default_reaction_emoji is None: pass else: - raise InvalidArgument("default_reaction_emoji must be of type: GuildEmoji | int | str | None") + raise TypeError("default_reaction_emoji must be of type: GuildEmoji | int | str | None") options["default_reaction_emoji"] = ( default_reaction_emoji._to_forum_reaction_payload() if default_reaction_emoji else None @@ -1803,7 +1803,7 @@ async def create_category( You do not have the proper permissions to create this channel. HTTPException Creating the channel failed. - InvalidArgument + TypeError or ValueError The permission overwrite information is not in proper form. """ options: dict[str, Any] = {} @@ -1998,7 +1998,7 @@ async def edit( You do not have permissions to edit the guild. HTTPException Editing the guild failed. - InvalidArgument + TypeError or ValueError The image format passed in to ``icon`` is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer. @@ -2047,7 +2047,7 @@ async def edit( if default_notifications is not MISSING: if not isinstance(default_notifications, NotificationLevel): - raise InvalidArgument("default_notifications field must be of type NotificationLevel") + raise TypeError("default_notifications field must be of type NotificationLevel") fields["default_message_notifications"] = default_notifications.value if afk_channel is not MISSING: @@ -2076,25 +2076,25 @@ async def edit( if owner is not MISSING: if self.owner_id != self._state.self_id: - raise InvalidArgument("To transfer ownership you must be the owner of the guild.") + raise ValueError("To transfer ownership you must be the owner of the guild.") fields["owner_id"] = owner.id if verification_level is not MISSING: if not isinstance(verification_level, VerificationLevel): - raise InvalidArgument("verification_level field must be of type VerificationLevel") + raise TypeError("verification_level field must be of type VerificationLevel") fields["verification_level"] = verification_level.value if explicit_content_filter is not MISSING: if not isinstance(explicit_content_filter, ContentFilter): - raise InvalidArgument("explicit_content_filter field must be of type ContentFilter") + raise TypeError("explicit_content_filter field must be of type ContentFilter") fields["explicit_content_filter"] = explicit_content_filter.value if system_channel_flags is not MISSING: if not isinstance(system_channel_flags, SystemChannelFlags): - raise InvalidArgument("system_channel_flags field must be of type SystemChannelFlags") + raise TypeError("system_channel_flags field must be of type SystemChannelFlags") fields["system_channel_flags"] = system_channel_flags.value @@ -2109,7 +2109,7 @@ async def edit( if "COMMUNITY" not in features: features.append("COMMUNITY") else: - raise InvalidArgument( + raise ValueError( "community field requires both rules_channel and public_updates_channel fields to be provided" ) else: @@ -2522,7 +2522,7 @@ async def prune_members( You do not have permissions to prune members. HTTPException An error occurred while pruning members. - InvalidArgument + TypeError or ValueError An integer was not passed for ``days``. Returns @@ -2533,7 +2533,7 @@ async def prune_members( """ if not isinstance(days, int): - raise InvalidArgument(f"Expected int for ``days``, received {days.__class__.__name__} instead.") + raise TypeError(f"Expected int for ``days``, received {days.__class__.__name__} instead.") role_ids = [str(role.id) for role in roles] if roles else [] data = await self._state.http.prune_members( @@ -2620,12 +2620,12 @@ async def estimate_pruned_members(self, *, days: int, roles: list[Snowflake] | u You do not have permissions to prune members. HTTPException An error occurred while fetching the prune members estimate. - InvalidArgument + TypeError or ValueError An integer was not passed for ``days``. """ if not isinstance(days, int): - raise InvalidArgument(f"Expected int for ``days``, received {days.__class__.__name__} instead.") + raise TypeError(f"Expected int for ``days``, received {days.__class__.__name__} instead.") role_ids = [str(role.id) for role in roles] if roles else [] data = await self._state.http.estimate_pruned_members(self.id, days, role_ids) @@ -3194,7 +3194,7 @@ async def create_role( You do not have permissions to create the role. HTTPException Creating the role failed. - InvalidArgument + TypeError or ValueError An invalid keyword argument was given. """ fields: dict[str, Any] = {} @@ -3222,7 +3222,7 @@ async def create_role( actual_colours.tertiary = None fields["colors"] = actual_colours._to_dict() else: - raise InvalidArgument( + raise TypeError( "colours parameter must be of type RoleColours, not {}".format(actual_colours.__class__.__name__) ) @@ -3293,11 +3293,11 @@ async def edit_role_positions(self, positions: dict[Snowflake, int], *, reason: You do not have permissions to move the roles. HTTPException Moving the roles failed. - InvalidArgument + TypeError or ValueError An invalid keyword argument was given. """ if not isinstance(positions, dict): - raise InvalidArgument("positions parameter expects a dict.") + raise TypeError("positions parameter expects a dict.") role_positions: list[dict[str, Any]] = [] for role, position in positions.items(): diff --git a/discord/http.py b/discord/http.py index 39b3432df1..b9472f9398 100644 --- a/discord/http.py +++ b/discord/http.py @@ -40,7 +40,6 @@ Forbidden, GatewayNotFound, HTTPException, - InvalidArgument, LoginFailure, NotFound, ) @@ -1640,7 +1639,7 @@ def create_guild_sticker( try: mime_type = get_mime_type_for_file(initial_bytes) - except InvalidArgument: + except ValueError: if initial_bytes.startswith(b"{"): mime_type = "application/json" else: diff --git a/discord/integrations.py b/discord/integrations.py index ac64f2d3d6..e969b01d33 100644 --- a/discord/integrations.py +++ b/discord/integrations.py @@ -31,7 +31,6 @@ from discord import utils from .enums import ExpireBehaviour, try_enum -from .errors import InvalidArgument from .user import User from .utils import MISSING from .utils.private import get_as_snowflake, parse_time @@ -253,13 +252,13 @@ async def edit( You do not have permission to edit the integration. HTTPException Editing the guild failed. - InvalidArgument + TypeError or ValueError ``expire_behaviour`` did not receive a :class:`ExpireBehaviour`. """ payload: dict[str, Any] = {} if expire_behaviour is not MISSING: if not isinstance(expire_behaviour, ExpireBehaviour): - raise InvalidArgument("expire_behaviour field must be of type ExpireBehaviour") + raise TypeError("expire_behaviour field must be of type ExpireBehaviour") payload["expire_behavior"] = expire_behaviour.value diff --git a/discord/interactions.py b/discord/interactions.py index 455b70b45a..8df025b38a 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -37,7 +37,7 @@ InteractionType, try_enum, ) -from .errors import ClientException, InteractionResponded, InvalidArgument +from .errors import ClientException, InteractionResponded from .file import File, VoiceMessage from .flags import MessageFlags from .guild import Guild @@ -1012,19 +1012,19 @@ async def send_message( else: payload["allowed_mentions"] = allowed_mentions.to_dict() if file is not None and files is not None: - raise InvalidArgument("cannot pass both file and files parameter to send()") + raise ValueError("cannot pass both file and files parameter to send()") if file is not None: if not isinstance(file, File): - raise InvalidArgument("file parameter must be File") + raise TypeError("file parameter must be File") else: files = [file] if files is not None: if len(files) > 10: - raise InvalidArgument("files parameter must be a list of up to 10 elements") + raise ValueError("files parameter must be a list of up to 10 elements") elif not all(isinstance(file, File) for file in files): - raise InvalidArgument("files parameter must be a list of File") + raise TypeError("files parameter must be a list of File") if any(isinstance(file, VoiceMessage) for file in files): flags = flags + MessageFlags(is_voice_message=True) @@ -1157,11 +1157,11 @@ async def edit_message( payload["components"] = [] if view is None else view.to_components() if file is not MISSING and files is not MISSING: - raise InvalidArgument("cannot pass both file and files parameter to edit_message()") + raise ValueError("cannot pass both file and files parameter to edit_message()") if file is not MISSING: if not isinstance(file, File): - raise InvalidArgument("file parameter must be a File") + raise TypeError("file parameter must be a File") else: files = [file] if "attachments" not in payload: @@ -1170,9 +1170,9 @@ async def edit_message( if files is not MISSING: if len(files) > 10: - raise InvalidArgument("files parameter must be a list of up to 10 elements") + raise ValueError("files parameter must be a list of up to 10 elements") elif not all(isinstance(file, File) for file in files): - raise InvalidArgument("files parameter must be a list of File") + raise TypeError("files parameter must be a list of File") if "attachments" not in payload: # we keep previous attachments when adding new files payload["attachments"] = [a.to_dict() for a in msg.attachments] diff --git a/discord/member.py b/discord/member.py index eeb50dae9c..dca229eeb1 100644 --- a/discord/member.py +++ b/discord/member.py @@ -39,7 +39,6 @@ from .asset import Asset from .colour import Colour from .enums import Status, try_enum -from .errors import InvalidArgument from .flags import MemberFlags from .object import Object from .permissions import Permissions @@ -871,7 +870,7 @@ async def edit( You do not have the proper permissions to the action requested. HTTPException The operation failed. - InvalidArgument + ValueError You tried to edit the avatar, banner, or bio of a member that is not the bot. """ http = self._state.http @@ -942,7 +941,7 @@ async def edit( bot_payload["bio"] = bio or "" if bot_payload and not me: - raise InvalidArgument("Can only edit avatar, banner, or bio for the bot's member.") + raise ValueError("Can only edit avatar, banner, or bio for the bot's member.") if payload: data = await http.edit_member(guild_id, self.id, reason=reason, **payload) diff --git a/discord/message.py b/discord/message.py index 9c140538ca..49053e705e 100644 --- a/discord/message.py +++ b/discord/message.py @@ -47,7 +47,6 @@ from .embeds import Embed from .emoji import AppEmoji, GuildEmoji from .enums import ChannelType, MessageReferenceType, MessageType, try_enum -from .errors import InvalidArgument from .file import File from .flags import AttachmentFlags, MessageFlags from .guild import Guild @@ -123,7 +122,7 @@ def convert_emoji_reaction(emoji): # No existing emojis have <> in them, so this should be okay. return emoji.strip("<>") - raise InvalidArgument( + raise TypeError( f"emoji argument must be str, GuildEmoji, AppEmoji, or Reaction not {emoji.__class__.__name__}." ) @@ -1665,7 +1664,7 @@ async def edit( Forbidden Tried to suppress a message without permissions or edited a message's content or embed that isn't yours. - ~discord.InvalidArgument + TypeError or ValueError You specified both ``embed`` and ``embeds``, specified both ``file`` and ``files``, or either``file`` or ``files`` were of the wrong type. @@ -1675,7 +1674,7 @@ async def edit( if content is not MISSING: payload["content"] = str(content) if content is not None else None if embed is not MISSING and embeds is not MISSING: - raise InvalidArgument("cannot pass both embed and embeds parameter to edit()") + raise ValueError("cannot pass both embed and embeds parameter to edit()") if embed is not MISSING: payload["embeds"] = [] if embed is None else [embed.to_dict()] @@ -1705,7 +1704,7 @@ async def edit( if view and view.is_components_v2(): flags.is_components_v2 = True if file is not MISSING and files is not MISSING: - raise InvalidArgument("cannot pass both file and files parameter to edit()") + raise ValueError("cannot pass both file and files parameter to edit()") if flags.value != self.flags.value: payload["flags"] = flags.value @@ -1713,13 +1712,13 @@ async def edit( if file is not MISSING or files is not MISSING: if file is not MISSING: if not isinstance(file, File): - raise InvalidArgument("file parameter must be of type File") + raise TypeError("file parameter must be of type File") files = [file] else: if len(files) > 10: - raise InvalidArgument("files parameter must be a list of up to 10 elements") + raise ValueError("files parameter must be a list of up to 10 elements") elif not all(isinstance(file, File) for file in files): - raise InvalidArgument("files parameter must be a list of File") + raise TypeError("files parameter must be a list of File") if "attachments" not in payload: # don't want it to remove any attachments when we just add a new file @@ -1850,7 +1849,7 @@ async def add_reaction(self, emoji: EmojiInputType) -> None: You do not have the proper permissions to react to the message. NotFound The emoji you specified was not found. - InvalidArgument + TypeError or ValueError The emoji parameter is invalid. """ @@ -1885,7 +1884,7 @@ async def remove_reaction(self, emoji: EmojiInputType | Reaction, member: Snowfl You do not have the proper permissions to remove the reaction. NotFound The member or emoji you specified was not found. - InvalidArgument + TypeError or ValueError The emoji parameter is invalid. """ @@ -1920,7 +1919,7 @@ async def clear_reaction(self, emoji: EmojiInputType | Reaction) -> None: You do not have the proper permissions to clear the reaction. NotFound The emoji you specified was not found. - InvalidArgument + TypeError or ValueError The emoji parameter is invalid. """ @@ -1983,11 +1982,11 @@ async def create_thread( You do not have permissions to create a thread. HTTPException Creating the thread failed. - InvalidArgument + TypeError or ValueError This message does not have guild info attached. """ if self.guild is None: - raise InvalidArgument("This message does not have guild info attached.") + raise ValueError("This message does not have guild info attached.") default_auto_archive_duration: ThreadArchiveDuration = getattr( self.channel, "default_auto_archive_duration", 1440 @@ -2023,7 +2022,7 @@ async def reply(self, content: str | None = None, **kwargs) -> Message: Sending the message failed. ~discord.Forbidden You do not have the proper permissions to send the message. - ~discord.InvalidArgument + TypeError or ValueError The ``files`` list is not of the appropriate size, or you specified both ``file`` and ``files``. """ @@ -2054,7 +2053,7 @@ async def forward_to(self, channel: MessageableChannel | PartialMessageableChann Sending the message failed. ~discord.Forbidden You do not have the proper permissions to send the message. - ~discord.InvalidArgument + TypeError or ValueError The ``files`` list is not of the appropriate size, or you specified both ``file`` and ``files``. """ @@ -2319,7 +2318,7 @@ async def edit(self, **fields: Any) -> Message | None: embeds = fields.pop("embeds", MISSING) if embed is not MISSING and embeds is not MISSING: - raise InvalidArgument("Cannot pass both embed and embeds parameters.") + raise ValueError("Cannot pass both embed and embeds parameters.") if embed is not MISSING: fields["embeds"] = [] if embed is None else [embed.to_dict()] diff --git a/discord/partial_emoji.py b/discord/partial_emoji.py index 1244cb4353..7613e420b9 100644 --- a/discord/partial_emoji.py +++ b/discord/partial_emoji.py @@ -30,7 +30,6 @@ from . import utils from .asset import Asset, AssetMixin -from .errors import InvalidArgument from .utils.private import get_as_snowflake __all__ = ("PartialEmoji",) @@ -245,6 +244,6 @@ def url(self) -> str: async def read(self) -> bytes: if self.is_unicode_emoji(): - raise InvalidArgument("PartialEmoji is not a custom emoji") + raise ValueError("PartialEmoji is not a custom emoji") return await super().read() diff --git a/discord/reaction.py b/discord/reaction.py index 67be421ffe..524b12d78c 100644 --- a/discord/reaction.py +++ b/discord/reaction.py @@ -204,7 +204,7 @@ async def clear(self) -> None: You do not have the proper permissions to clear the reaction. NotFound The emoji you specified was not found. - InvalidArgument + TypeError The emoji parameter is invalid. """ await self.message.clear_reaction(self.emoji) diff --git a/discord/role.py b/discord/role.py index f65bd9fad5..22f9686776 100644 --- a/discord/role.py +++ b/discord/role.py @@ -32,7 +32,6 @@ from .asset import Asset from .colour import Colour -from .errors import InvalidArgument from .flags import RoleFlags from .mixins import Hashable from .permissions import Permissions @@ -513,10 +512,10 @@ def icon(self) -> Asset | None: async def _move(self, position: int, reason: str | None) -> None: if position <= 0: - raise InvalidArgument("Cannot move role to position 0 or below") + raise ValueError("Cannot move role to position 0 or below") if self.is_default(): - raise InvalidArgument("Cannot move default role") + raise ValueError("Cannot move default role") if self.position == position: return # Save discord the extra request. @@ -606,7 +605,7 @@ async def edit( You do not have permissions to change the role. HTTPException Editing the role failed. - InvalidArgument + ValueError An invalid position was given or the default role was asked to be moved. """ @@ -629,7 +628,7 @@ async def edit( colours = RoleColours.holographic() if colours is not MISSING: if not isinstance(colours, RoleColours): - raise InvalidArgument("colours must be a RoleColours object") + raise TypeError("colours must be a RoleColours object") if "ENHANCED_ROLE_COLORS" not in self.guild.features: colours.secondary = None colours.tertiary = None diff --git a/discord/scheduled_events.py b/discord/scheduled_events.py index d2af4b770e..3bb1f8375c 100644 --- a/discord/scheduled_events.py +++ b/discord/scheduled_events.py @@ -35,7 +35,7 @@ ScheduledEventStatus, try_enum, ) -from .errors import InvalidArgument, ValidationError +from .errors import ValidationError from .iterators import ScheduledEventSubscribersIterator from .mixins import Hashable from .object import Object @@ -353,7 +353,7 @@ async def edit( if cover is not MISSING: warn_deprecated("cover", "image", "2.7") if image is not MISSING: - raise InvalidArgument("cannot pass both `image` and `cover` to `ScheduledEvent.edit`") + raise ValueError("cannot pass both `image` and `cover` to `ScheduledEvent.edit`") else: image = cover diff --git a/discord/shard.py b/discord/shard.py index 2e59baa198..0fd6f713bd 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -515,7 +515,7 @@ async def change_presence( Raises ------ - InvalidArgument + TypeError If the ``activity`` parameter is not of proper type. """ diff --git a/discord/stage_instance.py b/discord/stage_instance.py index 8fdc508f41..967665f1d3 100644 --- a/discord/stage_instance.py +++ b/discord/stage_instance.py @@ -28,7 +28,6 @@ from typing import TYPE_CHECKING from .enums import StagePrivacyLevel, try_enum -from .errors import InvalidArgument from .mixins import Hashable from .utils import MISSING, Undefined from .utils.private import cached_slot_property @@ -144,7 +143,7 @@ async def edit( Raises ------ - InvalidArgument + TypeError If the ``privacy_level`` parameter is not the proper type. Forbidden You do not have permissions to edit the stage instance. @@ -159,7 +158,7 @@ async def edit( if privacy_level is not MISSING: if not isinstance(privacy_level, StagePrivacyLevel): - raise InvalidArgument("privacy_level field must be of type PrivacyLevel") + raise TypeError("privacy_level field must be of type PrivacyLevel") payload["privacy_level"] = privacy_level.value diff --git a/discord/template.py b/discord/template.py index e5336fd5ed..10945b43be 100644 --- a/discord/template.py +++ b/discord/template.py @@ -192,7 +192,7 @@ async def create_guild(self, name: str, icon: Any = None) -> Guild: ------ HTTPException Guild creation failed. - InvalidArgument + ValueError Invalid icon image format given. Must be PNG or JPG. """ if icon is not None: diff --git a/discord/ui/select.py b/discord/ui/select.py index 43cabd249c..25b39470ff 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -35,7 +35,6 @@ from ..components import SelectMenu, SelectOption from ..emoji import AppEmoji, GuildEmoji from ..enums import ChannelType, ComponentType -from ..errors import InvalidArgument from ..interactions import Interaction from ..member import Member from ..partial_emoji import PartialEmoji @@ -145,9 +144,9 @@ def __init__( id: int | None = None, ) -> None: if options and select_type is not ComponentType.string_select: - raise InvalidArgument("options parameter is only valid for string selects") + raise ValueError("options parameter is only valid for string selects") if channel_types and select_type is not ComponentType.channel_select: - raise InvalidArgument("channel_types parameter is only valid for channel selects") + raise ValueError("channel_types parameter is only valid for channel selects") super().__init__() self._selected_values: list[str] = [] self._interaction: Interaction | None = None @@ -242,7 +241,7 @@ def channel_types(self) -> list[ChannelType]: @channel_types.setter def channel_types(self, value: list[ChannelType]): if self._underlying.type is not ComponentType.channel_select: - raise InvalidArgument("channel_types can only be set on channel selects") + raise ValueError("channel_types can only be set on channel selects") self._underlying.channel_types = value @property @@ -253,7 +252,7 @@ def options(self) -> list[SelectOption]: @options.setter def options(self, value: list[SelectOption]): if self._underlying.type is not ComponentType.string_select: - raise InvalidArgument("options can only be set on string selects") + raise ValueError("options can only be set on string selects") if not isinstance(value, list): raise TypeError("options must be a list of SelectOption") if not all(isinstance(obj, SelectOption) for obj in value): diff --git a/discord/user.py b/discord/user.py index 046c251295..9fd5bee09c 100644 --- a/discord/user.py +++ b/discord/user.py @@ -478,7 +478,7 @@ async def edit( ------ HTTPException Editing your profile failed. - InvalidArgument + ValueError Wrong image format passed for ``avatar`` or ``banner``. """ payload: dict[str, Any] = {} diff --git a/discord/utils/private.py b/discord/utils/private.py index 951debc6d0..051515e4a3 100644 --- a/discord/utils/private.py +++ b/discord/utils/private.py @@ -32,7 +32,7 @@ overload, ) -from ..errors import HTTPException, InvalidArgument +from ..errors import HTTPException if TYPE_CHECKING: from ..invite import Invite @@ -91,7 +91,7 @@ def get_mime_type_for_file(data: bytes): elif data.startswith((b"\x49\x44\x33", b"\xff\xfb")): return "audio/mpeg" else: - raise InvalidArgument("Unsupported file type given") + raise ValueError("Unsupported file type given") def bytes_to_base64_data(data: bytes) -> str: diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index a11ac45913..1d91878e3a 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -44,7 +44,6 @@ DiscordServerError, Forbidden, HTTPException, - InvalidArgument, NotFound, ) from ..file import VoiceMessage @@ -641,7 +640,7 @@ def handle_message_parameters( payload = {} if embeds is not MISSING: if len(embeds) > 10: - raise InvalidArgument("embeds has a maximum of 10 elements.") + raise ValueError("embeds has a maximum of 10 elements.") payload["embeds"] = [e.to_dict() for e in embeds] if embed is not MISSING: @@ -931,7 +930,7 @@ async def edit( You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` ValueError The length of ``embeds`` was invalid - InvalidArgument + ValueError There was no token associated with this webhook. """ thread = MISSING @@ -1289,7 +1288,7 @@ def from_url( Raises ------ - InvalidArgument + ValueError The URL is invalid. """ m = re.search( @@ -1297,7 +1296,7 @@ def from_url( url, ) if m is None: - raise InvalidArgument("Invalid webhook URL given.") + raise ValueError("Invalid webhook URL given.") data: dict[str, Any] = m.groupdict() data["type"] = 1 @@ -1382,7 +1381,7 @@ async def fetch(self, *, prefer_auth: bool = True) -> Webhook: Could not fetch the webhook NotFound Could not find the webhook by this ID - InvalidArgument + ValueError This webhook does not have a token associated with it. """ adapter = async_context.get() @@ -1404,7 +1403,7 @@ async def fetch(self, *, prefer_auth: bool = True) -> Webhook: proxy_auth=self.proxy_auth, ) else: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") return Webhook( data, @@ -1440,11 +1439,11 @@ async def delete(self, *, reason: str | None = None, prefer_auth: bool = True): This webhook does not exist. Forbidden You do not have permissions to delete this webhook. - InvalidArgument + ValueError This webhook does not have a token associated with it. """ if self.token is None and self.auth_token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") adapter = async_context.get() @@ -1506,12 +1505,12 @@ async def edit( Editing the webhook failed. NotFound This webhook does not exist. - InvalidArgument + ValueError This webhook does not have a token associated with it, or it tried editing a channel without authentication. """ if self.token is None and self.auth_token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") payload = {} if name is not MISSING: @@ -1526,7 +1525,7 @@ async def edit( # If a channel is given, always use the authenticated endpoint if channel is not None: if self.auth_token is None: - raise InvalidArgument("Editing channel requires authenticated webhook") + raise ValueError("Editing channel requires authenticated webhook") payload["channel_id"] = channel.id data = await adapter.edit_webhook( @@ -1742,30 +1741,29 @@ async def send( TypeError You specified both ``embed`` and ``embeds`` or ``file`` and ``files``. ValueError - The length of ``embeds`` was invalid. - InvalidArgument - Either there was no token associated with this webhook, ``ephemeral`` was passed - with the improper webhook type, there was no state attached with this webhook when - giving it a dispatchable view, you specified both ``thread_name`` and ``thread``, - or ``applied_tags`` was passed with neither ``thread_name`` nor ``thread`` specified. + The length of ``embeds`` was invalid, there was no token associated with this webhook, + ``ephemeral`` was passed with the improper webhook type, there was no state attached + with this webhook when giving it a dispatchable view, you specified both ``thread_name`` + and ``thread``, or ``applied_tags`` was passed with neither ``thread_name`` nor ``thread`` + specified. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") previous_mentions: AllowedMentions | None = getattr(self._state, "allowed_mentions", None) if content is None: content = MISSING if thread and thread_name: - raise InvalidArgument("You cannot specify both a thread and thread_name") + raise ValueError("You cannot specify both a thread and thread_name") if applied_tags and not (thread or thread_name): - raise InvalidArgument("You cannot specify applied_tags without a thread") + raise ValueError("You cannot specify applied_tags without a thread") application_webhook = self.type is WebhookType.application if ephemeral and not application_webhook: - raise InvalidArgument("ephemeral messages can only be sent from application webhooks") + raise ValueError("ephemeral messages can only be sent from application webhooks") if application_webhook: wait = True @@ -1774,7 +1772,7 @@ async def send( if view is not MISSING: if isinstance(self._state, _WebhookState) and view and view.is_dispatchable(): - raise InvalidArgument("Dispatchable Webhook views require an associated state with the webhook") + raise ValueError("Dispatchable Webhook views require an associated state with the webhook") if ephemeral is True and view.timeout is None: view.timeout = 15 * 60.0 if not application_webhook: @@ -1868,12 +1866,12 @@ async def fetch_message(self, id: int, *, thread_id: int | None = None) -> Webho You do not have the permissions required to get a message. ~discord.HTTPException Retrieving the message failed. - InvalidArgument + TypeError or ValueError There was no token associated with this webhook. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") adapter = async_context.get() data = await adapter.get_webhook_message( @@ -1970,19 +1968,19 @@ async def edit_message( You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` ValueError The length of ``embeds`` was invalid - InvalidArgument + TypeError or ValueError There was no token associated with this webhook or the webhook had no state. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") with_components = False if view is not MISSING: if isinstance(self._state, _WebhookState) and view and view.is_dispatchable(): - raise InvalidArgument("Dispatchable Webhook views require an associated state with the webhook") + raise ValueError("Dispatchable Webhook views require an associated state with the webhook") self._state.prevent_view_updates_for(message_id) if self.type is not WebhookType.application: @@ -2054,7 +2052,7 @@ async def delete_message(self, message_id: int, *, thread_id: int | None = None) Deleted a message that is not yours. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") adapter = async_context.get() await adapter.delete_webhook_message( diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index acc15eadde..9cb43e33ff 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -46,7 +46,6 @@ DiscordServerError, Forbidden, HTTPException, - InvalidArgument, NotFound, ) from ..http import Route @@ -498,7 +497,7 @@ def edit( You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` ValueError The length of ``embeds`` was invalid - InvalidArgument + ValueError There was no token associated with this webhook. """ thread = MISSING @@ -701,7 +700,7 @@ def from_url( Raises ------ - InvalidArgument + ValueError The URL is invalid. """ m = re.search( @@ -709,7 +708,7 @@ def from_url( url, ) if m is None: - raise InvalidArgument("Invalid webhook URL given.") + raise ValueError("Invalid webhook URL given.") data: dict[str, Any] = m.groupdict() data["type"] = 1 @@ -749,7 +748,7 @@ def fetch(self, *, prefer_auth: bool = True) -> SyncWebhook: Could not fetch the webhook NotFound Could not find the webhook by this ID - InvalidArgument + ValueError This webhook does not have a token associated with it. """ adapter: WebhookAdapter = _get_webhook_adapter() @@ -759,7 +758,7 @@ def fetch(self, *, prefer_auth: bool = True) -> SyncWebhook: elif self.token: data = adapter.fetch_webhook_with_token(self.id, self.token, session=self.session) else: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") return SyncWebhook(data, self.session, token=self.auth_token, state=self._state) @@ -784,11 +783,11 @@ def delete(self, *, reason: str | None = None, prefer_auth: bool = True) -> None This webhook does not exist. Forbidden You do not have permissions to delete this webhook. - InvalidArgument + ValueError This webhook does not have a token associated with it. """ if self.token is None and self.auth_token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") adapter: WebhookAdapter = _get_webhook_adapter() @@ -835,12 +834,12 @@ def edit( Editing the webhook failed. NotFound This webhook does not exist. - InvalidArgument + ValueError This webhook does not have a token associated with it, or it tried editing a channel without authentication. """ if self.token is None and self.auth_token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") payload = {} if name is not MISSING: @@ -855,7 +854,7 @@ def edit( # If a channel is given, always use the authenticated endpoint if channel is not None: if self.auth_token is None: - raise InvalidArgument("Editing channel requires authenticated webhook") + raise ValueError("Editing channel requires authenticated webhook") payload["channel_id"] = channel.id data = adapter.edit_webhook( @@ -1020,20 +1019,20 @@ def send( You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` ValueError The length of ``embeds`` was invalid - InvalidArgument + ValueError There was no token associated with this webhook, or you specified both a thread to send to and a thread to create (the ``thread`` and ``thread_name`` parameters). """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") previous_mentions: AllowedMentions | None = getattr(self._state, "allowed_mentions", None) if content is None: content = MISSING if thread and thread_name: - raise InvalidArgument("You cannot specify both a thread and a thread name") + raise ValueError("You cannot specify both a thread and a thread name") params = handle_message_parameters( content=content, @@ -1092,12 +1091,12 @@ def fetch_message(self, id: int, *, thread_id: int | None = None) -> SyncWebhook You do not have the permissions required to get a message. ~discord.HTTPException Retrieving the message failed. - InvalidArgument + ValueError There was no token associated with this webhook. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") adapter: WebhookAdapter = _get_webhook_adapter() data = adapter.get_webhook_message( @@ -1165,12 +1164,12 @@ def edit_message( You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` ValueError The length of ``embeds`` was invalid - InvalidArgument + ValueError There was no token associated with this webhook. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") previous_mentions: AllowedMentions | None = getattr(self._state, "allowed_mentions", None) params = handle_message_parameters( @@ -1224,7 +1223,7 @@ def delete_message(self, message_id: int, *, thread_id: int | None = None) -> No Deleted a message that is not yours. """ if self.token is None: - raise InvalidArgument("This webhook does not have a token associated with it") + raise ValueError("This webhook does not have a token associated with it") adapter: WebhookAdapter = _get_webhook_adapter() adapter.delete_webhook_message(