mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
Replace trigger_typing with awaiting typing context manager
This commit is contained in:
@ -1544,32 +1544,30 @@ class Messageable:
|
||||
await ret.delete(delay=delete_after)
|
||||
return ret
|
||||
|
||||
async def trigger_typing(self) -> None:
|
||||
"""|coro|
|
||||
|
||||
Triggers a *typing* indicator to the destination.
|
||||
|
||||
*Typing* indicator will go away after 10 seconds, or after a message is sent.
|
||||
"""
|
||||
|
||||
channel = await self._get_channel()
|
||||
await self._state.http.send_typing(channel.id)
|
||||
|
||||
def typing(self) -> Typing:
|
||||
"""Returns an asynchronous context manager that allows you to type for an indefinite period of time.
|
||||
|
||||
This is useful for denoting long computations in your bot.
|
||||
"""Returns an asynchronous context manager that allows you to send a typing indicator to
|
||||
the destination for an indefinite period of time, or 10 seconds if the context manager
|
||||
is called using ``await``.
|
||||
|
||||
Example Usage: ::
|
||||
|
||||
async with channel.typing():
|
||||
# simulate something heavy
|
||||
await asyncio.sleep(10)
|
||||
await asyncio.sleep(20)
|
||||
|
||||
await channel.send('done!')
|
||||
await channel.send('Done!')
|
||||
|
||||
Example Usage: ::
|
||||
|
||||
await channel.typing()
|
||||
# Do some computational magic for about 10 seconds
|
||||
await channel.send('Done!')
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
This no longer works with the ``with`` syntax, ``async with`` must be used instead.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
Added functionality to ``await`` the context manager to send a typing indicator for 10 seconds.
|
||||
"""
|
||||
return Typing(self)
|
||||
|
||||
|
Reference in New Issue
Block a user