diff --git a/CHANGELOG.md b/CHANGELOG.md index bad2225448..cc0477f08b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,12 @@ These changes are available on the `master` branch, but have not yet been releas - Fixed `Interaction.channel` not being resolved with user-installed commands ran in guilds which the bot is not a member of. ([#3047](https://github.com/Pycord-Development/pycord/pull/3047)) +- Fixed `Interaction.respond` and `ApplicationContext.respond` methods to explicitly + list their accepted parameters. + ([#3061](https://github.com/Pycord-Development/pycord/pull/3061)) +- Fixed an issue where the optional parameters of `InteractionResponse.send_message` + weren't type hinted as optional. + ([#3061](https://github.com/Pycord-Development/pycord/pull/3061)) ### Deprecated diff --git a/discord/commands/context.py b/discord/commands/context.py index 73a6b39a45..b9d6f8eff0 100644 --- a/discord/commands/context.py +++ b/discord/commands/context.py @@ -25,7 +25,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, TypeVar +from typing import TYPE_CHECKING, Any, TypeVar, overload import discord.abc from discord.interactions import Interaction, InteractionMessage, InteractionResponse @@ -38,15 +38,19 @@ import discord - from .. import Bot + from .. import AllowedMentions, Bot from ..client import ClientUser from ..cog import Cog + from ..embeds import Embed + from ..file import File from ..guild import Guild from ..interactions import InteractionChannel from ..member import Member from ..message import Message from ..permissions import Permissions + from ..poll import Poll from ..state import ConnectionState + from ..ui import BaseView from ..user import User from ..voice_client import VoiceClient from ..webhook import WebhookMessage @@ -277,12 +281,39 @@ def attachment_size_limit(self) -> int: def send_modal(self) -> Callable[..., Awaitable[Interaction]]: return self.interaction.response.send_modal - @property + @overload + async def respond( + self, + content: Any | None = None, + embed: Embed | None = None, + view: BaseView | None = None, + tts: bool = False, + ephemeral: bool = False, + allowed_mentions: AllowedMentions | None = None, + file: File | None = None, + files: list[File] | None = None, + poll: Poll | None = None, + delete_after: float | None = None, + ) -> Interaction | WebhookMessage: ... + + @overload + async def respond( + self, + content: Any | None = None, + embeds: list[Embed] | None = None, + view: BaseView | None = None, + tts: bool = False, + ephemeral: bool = False, + allowed_mentions: AllowedMentions | None = None, + file: File | None = None, + files: list[File] | None = None, + poll: Poll | None = None, + delete_after: float | None = None, + ) -> Interaction | WebhookMessage: ... + @discord.utils.copy_doc(Interaction.respond) - def respond( - self, *args, **kwargs - ) -> Callable[..., Awaitable[Interaction | WebhookMessage]]: - return self.interaction.respond + async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage: + return await self.interaction.respond(*args, **kwargs) @property @discord.utils.copy_doc(InteractionResponse.send_message) diff --git a/discord/interactions.py b/discord/interactions.py index 47498c6946..3578ca2f09 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -27,7 +27,7 @@ import asyncio import datetime -from typing import TYPE_CHECKING, Any, Coroutine, Union +from typing import TYPE_CHECKING, Any, Coroutine, Union, overload from . import utils from .channel import ChannelType, PartialMessageable, _threaded_channel_factory @@ -699,12 +699,75 @@ async def delete_original_message(self, **kwargs): """ return await self.delete_original_response(**kwargs) + @overload + async def respond( + self, + content: Any | None = None, + embed: Embed | None = None, + view: BaseView | None = None, + tts: bool = False, + ephemeral: bool = False, + allowed_mentions: AllowedMentions | None = None, + file: File | None = None, + files: list[File] | None = None, + poll: Poll | None = None, + delete_after: float | None = None, + ) -> Interaction | WebhookMessage: ... + + @overload + async def respond( + self, + content: Any | None = None, + embeds: list[Embed] | None = None, + view: BaseView | None = None, + tts: bool = False, + ephemeral: bool = False, + allowed_mentions: AllowedMentions | None = None, + file: File | None = None, + files: list[File] | None = None, + poll: Poll | None = None, + delete_after: float | None = None, + ) -> Interaction | WebhookMessage: ... + async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage: """|coro| Sends either a response or a message using the followup webhook determined by whether the interaction has been responded to or not. + Parameters + ---------- + content: Optional[:class:`str`] + The content of the message to send. + embeds: List[:class:`Embed`] + A list of embeds to send with the content. Maximum of 10. This cannot + be mixed with the ``embed`` parameter. + embed: :class:`Embed` + The rich embed for the content to send. This cannot be mixed with + ``embeds`` parameter. + tts: :class:`bool` + Indicates if the message should be sent using text-to-speech. + view: :class:`discord.ui.BaseView` + The view to send with the message. + ephemeral: :class:`bool` + Indicates if the message should only be visible to the user who started the interaction. + If a view is sent with an ephemeral message, and it has no timeout set then the timeout + is set to 15 minutes. + allowed_mentions: :class:`AllowedMentions` + Controls the mentions being processed in this message. + See :meth:`.abc.Messageable.send` for more information. + delete_after: :class:`float` + If provided, the number of seconds to wait in the background + before deleting the message we just sent. + file: :class:`File` + The file to upload. + files: List[:class:`File`] + A list of files to upload. Must be a maximum of 10. + poll: :class:`Poll` + The poll to send. + + .. versionadded:: 2.6 + Returns ------- Union[:class:`discord.Interaction`, :class:`discord.WebhookMessage`]: @@ -951,16 +1014,16 @@ async def send_message( self, content: Any | None = None, *, - embed: Embed = None, - embeds: list[Embed] = None, - view: BaseView = None, + embed: Embed | None = None, + embeds: list[Embed] | None = None, + view: BaseView | None = None, tts: bool = False, ephemeral: bool = False, - allowed_mentions: AllowedMentions = None, - file: File = None, - files: list[File] = None, - poll: Poll = None, - delete_after: float = None, + allowed_mentions: AllowedMentions | None = None, + file: File | None = None, + files: list[File] | None = None, + poll: Poll | None = None, + delete_after: float | None = None, ) -> Interaction: """|coro|