Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

EmreTech
Copy link
Collaborator

Summary

This PR moves listeners from commands.Bot to nextcord.Client. Closes #892.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have run task pyright and fixed the relevant issues.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@EmreTech EmreTech added p: low Priority: low - not important to be worked on s: awaiting review Status: the issue or PR is awaiting reviews t: refactor Type: refactor - this is a code change but does not fix a bug/add features labels Nov 23, 2022
Copy link
Collaborator

@Skelmis Skelmis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested, lgtm

nextcord/ext/commands/bot.py Show resolved Hide resolved
nextcord/ext/commands/bot.py Show resolved Hide resolved
nextcord/client.py Outdated Show resolved Hide resolved
nextcord/client.py Outdated Show resolved Hide resolved
Co-authored-by: spifory <luvuyosilubane50@gmail.com>
Copy link
Member

@ooliver1 ooliver1 left a 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"])

nextcord/client.py Show resolved Hide resolved
@ooliver1 ooliver1 added s: in progress Status: the issue or PR is in development/progress 3.0 The issue/PR should go for the 3.0 release and removed s: awaiting review Status: the issue or PR is awaiting reviews labels Mar 23, 2024
@ooliver1 ooliver1 modified the milestones: 2.6, 3.0 Mar 23, 2024
@EmreTech EmreTech requested a review from ooliver1 May 22, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 The issue/PR should go for the 3.0 release p: low Priority: low - not important to be worked on s: in progress Status: the issue or PR is in development/progress t: refactor Type: refactor - this is a code change but does not fix a bug/add features
Projects
No open projects
Status: In Cycle
Development

Successfully merging this pull request may close these issues.

Port event listeners from commands.Bot -> nextcord.Client
5 participants