Skip to content

Commit 473c416

Browse files
authored
Merge branch 'Pycord-Development:master' into master
2 parents 0846c09 + 5587fb6 commit 473c416

File tree

16 files changed

+508
-13
lines changed

16 files changed

+508
-13
lines changed

.github/CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ If the bug report is missing this information then it'll take us longer to fix t
3434

3535
Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is consistent to that found in the project. This project follows PEP-8 guidelines (mostly) with a column limit of 125.
3636

37+
### Licensing
38+
39+
By submitting a pull request, you agree that; 1) You hold the copyright on all submitted code inside said pull request; 2) You agree to transfer all rights to the owner of this repository, and; 3) If you are found to be in fault with any of the above, we shall not be held responsible in any way after the pull request has been merged.
40+
3741
### Git Commit Guidelines
3842

3943
- Use present tense (e.g. "Add feature" not "Added feature")

about.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# About
22
## What Happened to Discord.py?
3-
Rapptz, also known as Danny, the maintainer and core developer of discord.py will no longer be updating it. Here's his full explanation: https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1 <br>
3+
Rapptz, also known as Danny, the maintainer and core developer of discord.py will no longer be updating it. Here's his [Full explanation](https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1)
4+
</br>
45
[Here](https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1#FAQ) is a FAQ written by him.
56

67
## What is Pycord?
78
Pycord ("py-cord" on PyPI) is a maintained fork of discord.py which will be updated with new changes to the API. Pycord was created by a group of developers that want to continue developing this Python module.
89

910
## Features
1011
Pycord v1.7.3 is the same as discord.py v1.7.3. However Pycord v2.0.0 will support interactions and other features introduces in v2.0.0a as it's a fork of the master branch. <br>
11-
We also have a FAQ channel in our Discord server. You can [click here](https://discord.gg/nRMbjMnxCz) to join.
12+
We also have a FAQ channel in our Discord server. You can [click here](https://discord.gg/nRMbjMnxCz) to join.

discord/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from .threads import *
6262
from .bot import *
6363
from .app import *
64+
from .welcome_screen import *
6465

6566

6667
class VersionInfo(NamedTuple):

discord/app/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def invoke(self, ctx: InteractionContext) -> None:
169169

170170
class Option:
171171
def __init__(
172-
self, input_type: SlashCommandOptionType, /, description: str, **kwargs
172+
self, input_type, /, description: str, **kwargs
173173
) -> None:
174174
self.name: Optional[str] = kwargs.pop("name", None)
175175
self.description = description

discord/bot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ async def handle_interaction(self, interaction: Interaction) -> None:
247247
context = await self.get_application_context(interaction)
248248
await command.invoke(context)
249249

250-
def slash_command(self, **kwargs) -> SlashCommand:
250+
def slash_command(self, **kwargs):
251251
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
252252
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
253253
This shortcut is made specifically for :class:`.SlashCommand`.
@@ -262,7 +262,7 @@ def slash_command(self, **kwargs) -> SlashCommand:
262262
"""
263263
return self.application_command(cls=SlashCommand, **kwargs)
264264

265-
def user_command(self, **kwargs) -> UserCommand:
265+
def user_command(self, **kwargs):
266266
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
267267
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
268268
This shortcut is made specifically for :class:`.UserCommand`.
@@ -277,7 +277,7 @@ def user_command(self, **kwargs) -> UserCommand:
277277
"""
278278
return self.application_command(cls=UserCommand, **kwargs)
279279

280-
def message_command(self, **kwargs) -> MessageCommand:
280+
def message_command(self, **kwargs):
281281
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
282282
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
283283
This shortcut is made specifically for :class:`.MessageCommand`.

discord/channel.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
import discord.abc
4747
from .permissions import PermissionOverwrite, Permissions
48-
from .enums import ChannelType, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode
48+
from .enums import ChannelType, InviteTarget, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode
4949
from .mixins import Hashable
5050
from .object import Object
5151
from . import utils
@@ -55,6 +55,7 @@
5555
from .stage_instance import StageInstance
5656
from .threads import Thread
5757
from .iterators import ArchivedThreadIterator
58+
from .invite import Invite
5859

5960
__all__ = (
6061
'TextChannel',
@@ -1037,6 +1038,64 @@ async def edit(self, *, reason=None, **options):
10371038
# the payload will always be the proper channel payload
10381039
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
10391040

1041+
async def create_activity_invite(self, event:str, **kwargs) -> Invite:
1042+
"""|coro|
1043+
1044+
A shortcut method that creates an instant activity invite.
1045+
1046+
You must have the :attr:`~discord.Permissions.create_instant_invite` permission to
1047+
do this.
1048+
1049+
Parameters
1050+
------------
1051+
event: :class:`str`
1052+
The event to create an invite for.
1053+
max_age: :class:`int`
1054+
How long the invite should last in seconds. If it's 0 then the invite
1055+
doesn't expire. Defaults to ``0``.
1056+
max_uses: :class:`int`
1057+
How many uses the invite could be used for. If it's 0 then there
1058+
are unlimited uses. Defaults to ``0``.
1059+
temporary: :class:`bool`
1060+
Denotes that the invite grants temporary membership
1061+
(i.e. they get kicked after they disconnect). Defaults to ``False``.
1062+
unique: :class:`bool`
1063+
Indicates if a unique invite URL should be created. Defaults to True.
1064+
If this is set to ``False`` then it will return a previously created
1065+
invite.
1066+
reason: Optional[:class:`str`]
1067+
The reason for creating this invite. Shows up on the audit log.
1068+
1069+
1070+
Raises
1071+
-------
1072+
InvalidArgument
1073+
If the event is not a valid event.
1074+
~discord.HTTPException
1075+
Invite creation failed.
1076+
1077+
Returns
1078+
--------
1079+
:class:`~discord.Invite`
1080+
The invite that was created.
1081+
"""
1082+
1083+
application_ids = {
1084+
'youtube' : 755600276941176913,
1085+
'poker' : 755827207812677713,
1086+
'betrayal': 773336526917861400,
1087+
'fishing' : 814288819477020702,
1088+
'chess' : 832012774040141894,
1089+
}
1090+
event = application_ids.get(event)
1091+
if event is None:
1092+
raise InvalidArgument('Invalid event.')
1093+
1094+
return await self.create_invite(
1095+
target_type=InviteTarget.embedded_application,
1096+
target_application_id=event,
1097+
**kwargs
1098+
)
10401099

10411100
class StageChannel(VocalGuildChannel):
10421101
"""Represents a Discord guild stage channel.

discord/colour.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,13 @@ def yellow(cls: Type[CT]) -> CT:
325325
"""
326326
return cls(0xFEE75C)
327327

328+
@classmethod
329+
def nitro_pink(cls: Type[CT]) -> CT:
330+
"""A factory method that returns a :class:`Colour` with a value of ``0xf47fff``.
331+
332+
.. versionadded:: 2.0
333+
"""
334+
return cls(0xf47fff)
335+
328336

329337
Color = Colour

discord/guild.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from .threads import Thread, ThreadMember
7777
from .sticker import GuildSticker
7878
from .file import File
79+
from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
7980

8081

8182
__all__ = (
@@ -2942,3 +2943,103 @@ async def change_voice_state(
29422943
ws = self._state._get_websocket(self.id)
29432944
channel_id = channel.id if channel else None
29442945
await ws.voice_state(self.id, channel_id, self_mute, self_deaf)
2946+
2947+
async def welcome_screen(self):
2948+
"""|coro|
2949+
2950+
Returns the :class:`WelcomeScreen` of the guild.
2951+
2952+
The guild must have ``COMMUNITY`` in :attr:`~Guild.features`.
2953+
2954+
You must have the :attr:`~Permissions.manage_guild` permission in order to get this.
2955+
2956+
.. versionadded:: 2.0
2957+
2958+
Raises
2959+
-------
2960+
Forbidden
2961+
You do not have the proper permissions to get this.
2962+
HTTPException
2963+
Retrieving the welcome screen failed somehow.
2964+
NotFound
2965+
The guild doesn't has a welcome screen or community feature is disabled.
2966+
2967+
2968+
Returns
2969+
--------
2970+
:class:`WelcomeScreen`
2971+
The welcome screen of guild.
2972+
"""
2973+
data = await self._state.http.get_welcome_screen(self.id)
2974+
return WelcomeScreen(data=data, guild=self)
2975+
2976+
2977+
@overload
2978+
async def edit_welcome_screen(
2979+
self,
2980+
*,
2981+
description: Optional[str] = ...,
2982+
welcome_channels: Optional[List[WelcomeChannel]] = ...,
2983+
enabled: Optional[bool] = ...,
2984+
) -> WelcomeScreen:
2985+
...
2986+
2987+
@overload
2988+
async def edit_welcome_screen(self) -> None:
2989+
...
2990+
2991+
2992+
async def edit_welcome_screen(self, **options):
2993+
"""|coro|
2994+
2995+
A shorthand for :attr:`WelcomeScreen.edit` without fetching the welcome screen.
2996+
2997+
You must have the :attr:`~Permissions.manage_guild` permission in the
2998+
guild to do this.
2999+
3000+
The guild must have ``COMMUNITY`` in :attr:`Guild.features`
3001+
3002+
Parameters
3003+
------------
3004+
3005+
description: Optional[:class:`str`]
3006+
The new description of welcome screen.
3007+
welcome_channels: Optional[List[:class:`WelcomeChannel`]]
3008+
The welcome channels. The order of the channels would be same as the passed list order.
3009+
enabled: Optional[:class:`bool`]
3010+
Whether the welcome screen should be displayed.
3011+
reason: Optional[:class:`str`]
3012+
The reason that shows up on audit log.
3013+
3014+
Raises
3015+
-------
3016+
3017+
HTTPException
3018+
Editing the welcome screen failed somehow.
3019+
Forbidden
3020+
You don't have permissions to edit the welcome screen.
3021+
NotFound
3022+
This welcome screen does not exist.
3023+
3024+
Returns
3025+
--------
3026+
3027+
:class:`WelcomeScreen`
3028+
The edited welcome screen.
3029+
"""
3030+
3031+
welcome_channels = options.get('welcome_channels', [])
3032+
welcome_channels_data = []
3033+
3034+
for channel in welcome_channels:
3035+
if not isinstance(channel, WelcomeScreenChannel):
3036+
raise TypeError('welcome_channels parameter must be a list of WelcomeScreenChannel.')
3037+
3038+
welcome_channels_data.append(channel.to_dict())
3039+
3040+
options['welcome_channels'] = welcome_channels_data
3041+
3042+
if options:
3043+
new = await self._state.http.edit_welcome_screen(self.id, options, reason=options.get('reason'))
3044+
return WelcomeScreen(data=new, guild=self)
3045+

discord/http.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,22 @@ def delete_channel_permissions(
14901490
) -> Response[None]:
14911491
r = Route('DELETE', '/channels/{channel_id}/permissions/{target}', channel_id=channel_id, target=target)
14921492
return self.request(r, reason=reason)
1493+
1494+
# Welcome Screen
1495+
1496+
def get_welcome_screen(self, guild_id: Snowflake) -> Response[welcome_screen.WelcomeScreen]:
1497+
return self.request(Route('GET', '/guilds/{guild_id}/welcome-screen', guild_id=guild_id))
1498+
1499+
def edit_welcome_screen(self, guild_id: Snowflake, payload: Any, *, reason: Optional[str] = None) -> Response[welcome_screen.WelcomeScreen]:
1500+
keys = (
1501+
'description',
1502+
'welcome_channels',
1503+
'enabled',
1504+
)
1505+
payload = {
1506+
key: val for key, val in payload.items() if key in keys
1507+
}
1508+
return self.request(Route('PATCH', '/guilds/{guild_id}/welcome-screen', guild_id=guild_id), json=payload, reason=reason)
14931509

14941510
# Voice management
14951511

discord/raw_models.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
from typing import TYPE_CHECKING, Optional, Set, List
2828

29+
from .enums import ChannelType, try_enum
30+
2931
if TYPE_CHECKING:
3032
from .types.raw_models import (
3133
MessageDeleteEvent,
@@ -34,11 +36,14 @@
3436
MessageUpdateEvent,
3537
ReactionClearEvent,
3638
ReactionClearEmojiEvent,
37-
IntegrationDeleteEvent
39+
IntegrationDeleteEvent,
40+
ThreadDeleteEvent,
3841
)
3942
from .message import Message
4043
from .partial_emoji import PartialEmoji
4144
from .member import Member
45+
from .threads import Thread
46+
4247

4348

4449
__all__ = (
@@ -49,6 +54,7 @@
4954
'RawReactionClearEvent',
5055
'RawReactionClearEmojiEvent',
5156
'RawIntegrationDeleteEvent',
57+
'RawThreadDeleteEvent',
5258
)
5359

5460

@@ -276,3 +282,33 @@ def __init__(self, data: IntegrationDeleteEvent) -> None:
276282
self.application_id: Optional[int] = int(data['application_id'])
277283
except KeyError:
278284
self.application_id: Optional[int] = None
285+
286+
class RawThreadDeleteEvent(_RawReprMixin):
287+
"""Represents the payload for :func:`on_raw_thread_delete` event.
288+
289+
.. versionadded:: 2.0
290+
291+
Attributes
292+
----------
293+
294+
thread_id: :class:`int`
295+
The ID of the thread that was deleted.
296+
thread_type: :class:`discord.ChannelType`
297+
The channel type of the deleted thread.
298+
guild_id: :class:`int`
299+
The ID of the guild the deleted thread belonged to.
300+
parent_id: :class:`int`
301+
The ID of the channel the thread belonged to.
302+
thread: Optional[:class:`discord.Thread`]
303+
The thread that was deleted. This may be ``None`` if deleted thread is not found in internal cache.
304+
"""
305+
__slots__ = ('thread_id', 'thread_type', 'guild_id', 'parent_id', 'thread')
306+
307+
def __init__(self, data: ThreadDeleteEvent) -> None:
308+
self.thread_id: int = int(data['id'])
309+
self.thread_type: ChannelType = try_enum(ChannelType, int(data['type']))
310+
self.guild_id: int = int(data['guild_id'])
311+
self.parent_id: int = int(data['parent_id'])
312+
self.thread: Optional[Thread] = None
313+
314+

0 commit comments

Comments
 (0)