New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move listeners to the main library #917
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested, lgtm
Co-authored-by: spifory <luvuyosilubane50@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine. Test code:
import os
from dotenv import load_dotenv
from nextcord import Client, Intents, Message
load_dotenv()
client = Client(intents=Intents(guilds=True, guild_messages=True, message_content=True))
@client.listen()
async def on_ready():
print("Bot is ready")
async def on_message(message: Message):
if message.content == "ping":
await message.channel.send("pong")
client.remove_listener(on_message)
client.add_listener(on_message)
client.run(os.environ["TOKEN"])
@@ -1292,6 +1297,92 @@ async def on_ready(): | |||
_log.debug("%s has successfully been registered as an event", coro.__name__) | |||
return coro | |||
|
|||
def add_listener(self, func: CoroFunc, name: str = MISSING) -> None: | |||
"""The non decorator alternative to :meth:`.listen`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure as to if these should have versionadded, since they have been added to Client
.
Summary
This PR moves listeners from
commands.Bot
tonextcord.Client
. Closes #892.Checklist
task pyright
and fixed the relevant issues.