Skip to content

Commit

Permalink
Merge branch 'master' into pomelo
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby authored May 17, 2023
2 parents 6ff41b9 + 6a69f66 commit c508f35
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ These changes are available on the `master` branch, but have not yet been releas
listeners. ([#2044](https://github.com/Pycord-Development/pycord/pull/2044))
- Fixed unloading of cogs having bridge commands.
([#2048](https://github.com/Pycord-Development/pycord/pull/2048))
- Fixed the Slash command syncronization method `indiviual`.
([#1925](https://github.com/Pycord-Development/pycord/pull/1925))

## [2.4.1] - 2023-03-20

Expand Down
37 changes: 28 additions & 9 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,21 +501,24 @@ def _register(
)

def register(
method: Literal["bulk", "upsert", "delete", "edit"], *args, **kwargs
method: Literal["bulk", "upsert", "delete", "edit"],
*args,
cmd_name: str = None,
guild_id: int | None = None,
**kwargs,
):
if kwargs.pop("_log", True):
if method == "bulk":
_log.debug(
f"Bulk updating commands {[c['name'] for c in args[0]]} for"
f" guild {guild_id}"
)
# TODO: Find where "cmd" is defined
elif method == "upsert":
_log.debug(f"Creating command {cmd['name']} for guild {guild_id}") # type: ignore
_log.debug(f"Creating command {cmd_name} for guild {guild_id}") # type: ignore
elif method == "edit":
_log.debug(f"Editing command {cmd['name']} for guild {guild_id}") # type: ignore
_log.debug(f"Editing command {cmd_name} for guild {guild_id}") # type: ignore
elif method == "delete":
_log.debug(f"Deleting command {cmd['name']} for guild {guild_id}") # type: ignore
_log.debug(f"Deleting command {cmd_name} for guild {guild_id}") # type: ignore
return _register(method, *args, **kwargs)

pending_actions = []
Expand Down Expand Up @@ -602,15 +605,31 @@ def register(
registered = []
for cmd in filtered_no_action:
if cmd["action"] == "delete":
await register("delete", cmd["command"])
await register(
"delete",
cmd["id"],
cmd_name=cmd["command"].name,
guild_id=guild_id,
)
continue
if cmd["action"] == "edit":
registered.append(
await register("edit", cmd["id"], cmd["command"].to_dict())
await register(
"edit",
cmd["id"],
cmd["command"].to_dict(),
cmd_name=cmd["command"].name,
guild_id=guild_id,
)
)
elif cmd["action"] == "upsert":
registered.append(
await register("upsert", cmd["command"].to_dict())
await register(
"upsert",
cmd["command"].to_dict(),
cmd_name=cmd["command"].name,
guild_id=guild_id,
)
)
else:
raise ValueError(f"Unknown action: {cmd['action']}")
Expand All @@ -628,7 +647,7 @@ def register(
)
else:
data = [cmd.to_dict() for cmd in pending]
registered = await register("bulk", data)
registered = await register("bulk", data, guild_id=guild_id)

for i in registered:
cmd = get(
Expand Down
4 changes: 2 additions & 2 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def __init__(
url: Any | None = None,
description: Any | None = None,
timestamp: datetime.datetime | None = None,
fields: list[EmbedField] = [],
fields: list[EmbedField] | None = None,
author: EmbedAuthor | None = None,
footer: EmbedFooter | None = None,
image: str | None = None,
Expand All @@ -374,7 +374,7 @@ def __init__(
if timestamp:
self.timestamp = timestamp

self._fields: list[EmbedField] = fields
self._fields: list[EmbedField] = fields if fields is not None else []

if author:
self.set_author(**author.to_dict())
Expand Down
12 changes: 6 additions & 6 deletions docs/api/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Event Reference

This section outlines the different types of events listened by :class:`Client`.

There are 4 ways to register an event, the first way is through the use of
There are 3 ways to register an event, the first way is through the use of
:meth:`Client.event`. The second way is through subclassing :class:`Client` and
overriding the specific events. The third way is through the use of :meth:`Client.listen`,
which can be used to assign multiple event handlers instead of only one like in :meth:`Client.event`.
The fourth way is through the use of :meth:`Client.once`, which serves as a one-time event listener. For example:
For example:

.. code-block:: python
:emphasize-lines: 17, 22
Expand Down Expand Up @@ -41,10 +41,10 @@ The fourth way is through the use of :meth:`Client.once`, which serves as a one-
async def on_message(message: discord.Message):
print(f"Received {message.content}")
# Runs only for the 1st 'on_message' event. Can be useful for listening to 'on_ready'
@client.once()
async def message(message: discord.Message):
print(f"Received {message.content}")
# Runs only for the 1st event dispatch. Can be useful for listening to 'on_ready'
@client.listen(once=True)
async def on_ready():
print("Client is ready!")
If an event handler raises an exception, :func:`on_error` will be called
Expand Down

0 comments on commit c508f35

Please sign in to comment.