Skip to content

Commit 499357c

Browse files
CodeWithSwastikizxxrToxicKidzLulalabyDorukyum
authored
Sync autocomplete and master (#357)
* Use full name for commands.Bot reference * Fix typo .-. Co-authored-by: ToxicKidz <[email protected]> * Fix user flag description * Add `guild.premium_progress_bar_enabled` * Add support for toggling `premium_progress_bar` * Remove duplicate file checks * Added an example for slash commands in cogs. * A few more flags * Update enums.py * Change app commands description from None to an empty string before get. * Look for guild_ids instead of description in register_commands. * Delete bypass-review.yml * Update discord/enums.py Co-authored-by: Middledot <[email protected]> * Code explanation with comments. * Update bot.py * Update discord/bot.py Co-authored-by: Dorukyum <[email protected]> * Add missing newline * return Interaction object in send_message Co-authored-by: Izhar Ahmad <[email protected]> Co-authored-by: ToxicKidz <[email protected]> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: Dorukyum <[email protected]> Co-authored-by: Dorukyum <[email protected]> Co-authored-by: Sengolda <[email protected]> Co-authored-by: BobDotCom <[email protected]> Co-authored-by: TheGamerX20 <[email protected]> Co-authored-by: Middledot <[email protected]> Co-authored-by: Sengolda <[email protected]> Co-authored-by: Krittick <[email protected]>
2 parents b850b09 + c098ca5 commit 499357c

File tree

10 files changed

+61
-58
lines changed

10 files changed

+61
-58
lines changed

.github/workflows/bypass-review.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

discord/bot.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
from .client import Client
4747
from .shard import AutoShardedClient
48-
from .utils import MISSING, get, async_all
48+
from .utils import MISSING, get, find, async_all
4949
from .commands import (
5050
SlashCommand,
5151
SlashCommandGroup,
@@ -189,7 +189,7 @@ async def register_commands(self) -> None:
189189
cmd = get(
190190
self.pending_application_commands,
191191
name=i["name"],
192-
description=i["description"],
192+
guild_ids=None,
193193
type=i["type"],
194194
)
195195
self.application_commands[i["id"]] = cmd
@@ -225,12 +225,7 @@ async def register_commands(self) -> None:
225225
raise
226226
else:
227227
for i in cmds:
228-
cmd = get(
229-
self.pending_application_commands,
230-
name=i["name"],
231-
description=i["description"],
232-
type=i["type"],
233-
)
228+
cmd = find(lambda cmd: cmd.name == i["name"] and cmd.type == i["type"] and int(i["guild_id"]) in cmd.guild_ids, self.pending_application_commands)
234229
self.application_commands[i["id"]] = cmd
235230

236231
# Permissions
@@ -463,7 +458,7 @@ def command(self, **kwargs):
463458
464459
.. note::
465460
466-
This decorator is overridden by :class:`commands.Bot`.
461+
This decorator is overridden by :class:`discord.ext.commands.Bot`.
467462
468463
.. versionadded:: 2.0
469464

discord/enums.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,13 @@ def __int__(self):
596596
return self.value
597597

598598

599+
class ApplicationType(Enum):
600+
game = 1
601+
music = 2
602+
ticketed_events = 3
603+
guild_role_subscriptions = 4
604+
605+
599606
class StagePrivacyLevel(Enum):
600607
public = 1
601608
closed = 2

discord/flags.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ def bug_hunter_level_2(self):
426426
""":class:`bool`: Returns ``True`` if the user is a Bug Hunter Level 2"""
427427
return UserFlags.bug_hunter_level_2.value
428428

429+
@flag_value
430+
def has_unread_urgent_messages(self):
431+
""":class:`bool`: Returns ``True`` if the user has a unread urgent messages."""
432+
return UserFlags.has_unread_urgent_messages.value
433+
429434
@flag_value
430435
def underage_deleted(self):
431436
""":class:`bool`: Returns ``True`` if the user has a pending deletion for being underage in DOB prompt"""

discord/guild.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class Guild(Hashable):
208208
- ``FEATURABLE``: Guild is able to be featured in Server Discovery.
209209
- ``HAS_DIRECTORY_ENTRY``: Unknown.
210210
- ``HUB``: Hubs contain a directory channel that let you find school-related, student-run servers for your school or university.
211+
- ``INTERNAL_EMPLOYEE_ONLY``: Indicates that only users with the staff badge can join the guild.
211212
- ``INVITE_SPLASH``: Guild's invite page can have a special splash.
212213
- ``LINKED_TO_HUB``: 'Guild is linked to a hub.
213214
- ``MEMBER_PROFILES``: Unknown.
@@ -239,6 +240,10 @@ class Guild(Hashable):
239240
The number goes from 0 to 3 inclusive.
240241
premium_subscription_count: :class:`int`
241242
The number of "boosts" this guild currently has.
243+
premium_progress_bar_enabled: :class:`bool`
244+
Indicates if the guild has premium progress bar enabled.
245+
246+
.. versionadded:: 2.0
242247
preferred_locale: Optional[:class:`str`]
243248
The preferred locale for the guild. Used when filtering Server Discovery
244249
results to a specific language.
@@ -269,6 +274,7 @@ class Guild(Hashable):
269274
'max_video_channel_users',
270275
'premium_tier',
271276
'premium_subscription_count',
277+
'premium_progress_bar_enabled',
272278
'preferred_locale',
273279
'nsfw_level',
274280
'_members',
@@ -449,6 +455,7 @@ def _from_data(self, guild: GuildPayload) -> None:
449455
self.max_video_channel_users: Optional[int] = guild.get('max_video_channel_users')
450456
self.premium_tier: int = guild.get('premium_tier', 0)
451457
self.premium_subscription_count: int = guild.get('premium_subscription_count') or 0
458+
self.premium_progress_bar_enabled: bool = guild.get('premium_progress_bar_enabled') or False
452459
self._system_channel_flags: int = guild.get('system_channel_flags', 0)
453460
self.preferred_locale: Optional[str] = guild.get('preferred_locale')
454461
self._discovery_splash: Optional[str] = guild.get('discovery_splash')
@@ -1370,6 +1377,7 @@ async def edit(
13701377
preferred_locale: str = MISSING,
13711378
rules_channel: Optional[TextChannel] = MISSING,
13721379
public_updates_channel: Optional[TextChannel] = MISSING,
1380+
premium_progress_bar_enabled: bool = MISSING,
13731381
) -> Guild:
13741382
r"""|coro|
13751383
@@ -1447,6 +1455,8 @@ async def edit(
14471455
The new channel that is used for public updates from Discord. This is only available to
14481456
guilds that contain ``PUBLIC`` in :attr:`Guild.features`. Could be ``None`` for no
14491457
public updates channel.
1458+
premium_progress_bar_enabled: :class:`bool`
1459+
Whether the guild should have premium progress bar enabled.
14501460
reason: Optional[:class:`str`]
14511461
The reason for editing this guild. Shows up on the audit log.
14521462
@@ -1577,6 +1587,9 @@ async def edit(
15771587
)
15781588

15791589
fields['features'] = features
1590+
1591+
if premium_progress_bar_enabled is not MISSING:
1592+
fields['premium_progress_bar_enabled'] = premium_progress_bar_enabled
15801593

15811594
data = await http.edit_guild(self.id, reason=reason, **fields)
15821595
return Guild(data=data, state=self._state)

discord/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ def edit_guild(self, guild_id: Snowflake, *, reason: Optional[str] = None, **fie
10771077
'rules_channel_id',
10781078
'public_updates_channel_id',
10791079
'preferred_locale',
1080+
'premium_progress_bar_enabled',
10801081
)
10811082

10821083
payload = {k: v for k, v in fields.items() if k in valid_keys}

discord/interactions.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ async def send_message(
475475
file: File = None,
476476
files: List[File] = None,
477477
delete_after: float = None
478-
) -> None:
478+
) -> Interaction:
479479
"""|coro|
480480
481481
Responds to this interaction by sending a message.
@@ -572,21 +572,6 @@ async def send_message(
572572
elif not all(isinstance(file, File) for file in files):
573573
raise InvalidArgument('files parameter must be a list of File')
574574

575-
if file is not None and files is not None:
576-
raise InvalidArgument('cannot pass both file and files parameter to send()')
577-
578-
if file is not None:
579-
if not isinstance(file, File):
580-
raise InvalidArgument('file parameter must be File')
581-
else:
582-
files = [file]
583-
584-
if files is not None:
585-
if len(files) > 10:
586-
raise InvalidArgument('files parameter must be a list of up to 10 elements')
587-
elif not all(isinstance(file, File) for file in files):
588-
raise InvalidArgument('files parameter must be a list of File')
589-
590575
parent = self._parent
591576
adapter = async_context.get()
592577
try:
@@ -615,7 +600,7 @@ async def delete():
615600
await asyncio.sleep(delete_after)
616601
await self._parent.delete_original_message()
617602
asyncio.ensure_future(delete(), loop=self._parent._state.loop)
618-
603+
return self._parent
619604

620605
async def edit_message(
621606
self,
@@ -884,4 +869,4 @@ async def inner_call(delay: float = delay):
884869

885870
asyncio.create_task(inner_call())
886871
else:
887-
await self._state._interaction.delete_original_message()
872+
await self._state._interaction.delete_original_message()

discord/types/guild.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class _GuildOptional(TypedDict, total=False):
6666
max_presences: Optional[int]
6767
max_members: int
6868
premium_subscription_count: int
69+
premium_progress_bar_enabled: bool
6970
max_video_channel_users: int
7071

7172

docs/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,9 @@ of :class:`enum.Enum`.
14371437
.. attribute:: team_user
14381438

14391439
The user is a Team User.
1440+
.. attribute:: partner_or_verification_application
1441+
1442+
Relates to partner/verification applications.
14401443
.. attribute:: system
14411444

14421445
The user is a system user (i.e. represents Discord officially).
@@ -1455,6 +1458,12 @@ of :class:`enum.Enum`.
14551458
.. attribute:: discord_certified_moderator
14561459

14571460
The user is a Discord Certified Moderator.
1461+
.. attribute:: bot_http_interactions
1462+
1463+
The bot has set an interactions endpoint url.
1464+
.. attribute:: spammer
1465+
1466+
The user is disabled for being a spammer.
14581467

14591468
.. class:: ActivityType
14601469

examples/app_commands/slash_cog.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from discord.ext import commands
2+
from discord.commands import slash_command # Importing the decorator that makes slash commands.
3+
4+
class Example(commands.Cog):
5+
def __init__(self, bot):
6+
self.bot = bot
7+
8+
@slash_command(guild_ids=[...]) # Create a slash command for the supplied guilds.
9+
async def hello(self, ctx):
10+
await ctx.respond("Hi, this is a slash command from a cog!")
11+
12+
13+
@slash_command() # Not passing in guild_ids creates a global slash command (might take an hour to register).
14+
async def hi(self, ctx):
15+
await ctx.respond(f"Hi, this is a global slash command from a cog!")
16+
17+
def setup(bot):
18+
bot.add_cog(Example(bot))

0 commit comments

Comments
 (0)