A stubs package for discord.py that adds overloads to the commands.Bot.listen decorator.
Project description
discord.py-listen-overloads
A stubs package for discord.py that adds overloads to the @commands.Bot.listen
decorator.
Installation
python -m pip install discord.py-listen-overloads
Or the development version:
python -m pip install "discord.py-listen-overloads @ git+https://github.com/Soheab/discord.py-listen-overloads"
The versions depends on the latest stable release of discord.py on PyPi.
For example if the discord.py version on PyPi is 2.5.1
then running the first command will also install discord.py-listen-overloads==2.5.1
and the development version will probably be 2.6.0a
.
You can also install this stub for specific discord.py version by adding ==the.version.here
from version 2.3.2
to the first command.
Example
Before:
bot = commands.Bot(**kwargs)
@bot.listen("on_typing") # no errors
async def on_typing_event(channel):
...
@bot.listen("non_extisting_event") # no errors
async def non_extisting_event(random: bool):
...
reveal_type(on_typing_event)
# Type of "on_typing_event" is "(channel: Unknown) -> Coroutine[Any, Any, None]"
reveal_type(non_extisting_event)
# Type of "non_extisting_event" is "(random: bool) -> Coroutine[Any, Any, None]"
After:
bot = commands.Bot(**kwargs)
@bot.listen("on_typing") # <--
# - Argument of type "(channel: Unknown) -> Coroutine[Any, Any, None]" cannot be assigned to parameter of type "TypingEvent"
# Type "(channel: Unknown) -> Coroutine[Any, Any, None]" cannot be assigned to type "(channel: Messageable, user: Member | User, when: datetime) -> Coroutine[Any, Any, Any]"
# Function accepts too many positional parameters; expected 1 but received 3
async def on_typing_event(channel):
...
@bot.listen("non_extisting_event") # <--
# DISCLAIMER: the error can be different for you but similar.
# - Argument of type "Literal['non_extisting_event']" cannot be assigned to parameter "name" of type "Literal['on_command', 'on_command_completion']" in function "listen"
# Type "Literal['non_extisting_event']" cannot be assigned to type "Literal['on_command', 'on_command_completion']"
# "Literal['non_extisting_event']" cannot be assigned to type "Literal['on_command']"
# "Literal['non_extisting_event']" cannot be assigned to type "Literal['on_command_completion']"
async def non_extisting_event(random: bool):
...
reveal_type(on_typing_event)
# Type of "on_typing_event" is "TypingEvent"
So now we know that the on_typing
is an existing event but non_extisting_event
is not. that is takes 3 parameters and all their types. Here
is the correct correct version that shouldn't error:
from typing import Any
import datetime
@bot.listen("on_typing") # no errors
async def on_typing_event(channel: discord.abc.Messageable, user: discord.Member | discord.User, when: datetime.datetime) -> Any:
...
Custom events are not supported unfortunately since that would defeat the whole point of such package.
Why?
Idk you're reading this.
But like isn't cool to be able to use events without having to pull up docs for it?
Contact
You can contact me on Discord at Soheab_
or mention me in the discord.py server. Also welcome to open an issue/pull-request on this repo for anything.
Credits
This package is heavily inpsired by bryanforbes's package called discord.py-stubs. It provides stubs for the whole library from versions 1.3.4.0 to the last 1.x release (1.7.3).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file discord.py-listen-overloads-2.3.2.tar.gz
.
File metadata
- Download URL: discord.py-listen-overloads-2.3.2.tar.gz
- Upload date:
- Size: 271.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05803df324e28ac4e3a8d2dad6383bc91bea9730ae797ef6c315dbca0f3976b6 |
|
MD5 | 763a11b6159f2eb3bccf6a8d117adf58 |
|
BLAKE2b-256 | 08b6be8b47b8fdb29522117534641422e09b219396afa68e485df5a6d24949a2 |
File details
Details for the file discord.py_listen_overloads-2.3.2-py3-none-any.whl
.
File metadata
- Download URL: discord.py_listen_overloads-2.3.2-py3-none-any.whl
- Upload date:
- Size: 396.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85549d21b18eba32486ec0cbf80be2df639ffa7861a83579d24ac707c0531c44 |
|
MD5 | 099ad36033768c23ac427425fe2f1949 |
|
BLAKE2b-256 | 5b6f532f64d6a63fe03f0ff05627ec4e5b0affd585604ad01de391fb69c6b5c2 |