Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

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).

Metadata

Release files for discord.py-listen-overloads 2.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord.py-listen-overloads 2.3.2
File Size Uploaded
discord.py-listen-overloads-2.3.2.tar.gz 271.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord.py-listen-overloads 2.3.2
File Interpreter ABI Platform
discord.py_listen_overloads-2.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 667.8 kB

Release files / discord.py-listen-overloads-2.3.2.tar.gz

Download URL discord.py-listen-overloads-2.3.2.tar.gz
Size 271.3 kB
Tags Source
SHA-256 checksum
How to use checksums
05803df324e28ac4e3a8d2dad6383bc91bea9730ae797ef6c315dbca0f3976b6
BLAKE2b-256 checksum
How to use checksums
08b6be8b47b8fdb29522117534641422e09b219396afa68e485df5a6d24949a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / discord.py_listen_overloads-2.3.2-py3-none-any.whl

Download URL discord.py_listen_overloads-2.3.2-py3-none-any.whl
Size 396.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85549d21b18eba32486ec0cbf80be2df639ffa7861a83579d24ac707c0531c44
BLAKE2b-256 checksum
How to use checksums
5b6f532f64d6a63fe03f0ff05627ec4e5b0affd585604ad01de391fb69c6b5c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

2.3.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page