Skip to content

Commit fe4ee70

Browse files
authored
Merge branch 'master' into slash
2 parents 32f2929 + 5d4e7a2 commit fe4ee70

File tree

20 files changed

+572
-32
lines changed

20 files changed

+572
-32
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")

README.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,20 @@ Quick Example
7272
7373
import discord
7474
75-
class MyClient(discord.Client):
76-
async def on_ready(self):
77-
print("Logged on as", self.user)
78-
79-
async def on_message(self, message):
80-
# don't respond to ourselves
81-
if message.author == self.user:
82-
return
83-
84-
if message.content == "ping":
85-
await message.channel.send("pong")
86-
87-
client = MyClient()
88-
client.run("token")
75+
bot = discord.Bot()
76+
77+
@bot.slash_command()
78+
async def hello(ctx, name: str = None):
79+
name = name or ctx.author.name
80+
await ctx.send(f"Hello {name}!")
81+
82+
@bot.user_command(name="Say Hello")
83+
async def hi(ctx, user):
84+
await ctx.send(f"{ctx.author.mention} says hello to {user.name}!")
85+
86+
bot.run("token")
8987
90-
Bot Example
88+
Normal Commands Example
9189
~~~~~~~~~~~~~
9290

9391
.. code:: py
@@ -110,4 +108,5 @@ Links
110108

111109
- `Documentation <https://pycord.readthedocs.io/en/latest/index.html>`_
112110
- `Official Discord Server <https://discord.gg/dK2qkEJ37N>`_
111+
- `Discord Developers <https://discord.gg/discord-developers>`_
113112
- `Discord API <https://discord.gg/discord-api>`_

discord/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
from .bot import *
6363
from .app import *
6464
from .cog import Cog
65+
from .welcome_screen import *
66+
6567

6668
class VersionInfo(NamedTuple):
6769
major: int

discord/app/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def _update_copy(self, kwargs: Dict[str, Any]):
466466

467467
class Option:
468468
def __init__(
469-
self, input_type: Any, /, description = None,**kwargs
469+
self, input_type: Any, /, description: str = None, **kwargs
470470
) -> None:
471471
self.name: Optional[str] = kwargs.pop("name", None)
472472
self.description = description or "No description provided"

discord/bot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def process_application_commands(self, interaction: Interaction) -> None:
232232
else:
233233
self.dispatch('application_command_completion', ctx)
234234

235-
def slash_command(self, **kwargs) -> SlashCommand:
235+
def slash_command(self, **kwargs):
236236
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
237237
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
238238
This shortcut is made specifically for :class:`.SlashCommand`.
@@ -247,7 +247,7 @@ def slash_command(self, **kwargs) -> SlashCommand:
247247
"""
248248
return self.application_command(cls=SlashCommand, **kwargs)
249249

250-
def user_command(self, **kwargs) -> UserCommand:
250+
def user_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:`.UserCommand`.
@@ -262,7 +262,7 @@ def user_command(self, **kwargs) -> UserCommand:
262262
"""
263263
return self.application_command(cls=UserCommand, **kwargs)
264264

265-
def message_command(self, **kwargs) -> MessageCommand:
265+
def message_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:`.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/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,17 @@ async def login(self, token: str) -> None:
460460
461461
Raises
462462
------
463+
TypeError
464+
The token was in invalid type.
463465
:exc:`.LoginFailure`
464466
The wrong credentials are passed.
465467
:exc:`.HTTPException`
466468
An unknown HTTP related error occurred,
467469
usually when it isn't 200 or the known incorrect credentials
468470
passing status code.
469471
"""
472+
if not isinstance(token, str):
473+
raise TypeError(f"token must be of type str, not {token.__class__.__name__}")
470474

471475
_log.info('logging in using static token')
472476

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/embeds.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,22 @@ def set_image(self: E, *, url: MaybeEmpty[Any]) -> E:
424424

425425
return self
426426

427+
def remove_image(self: E) -> E:
428+
"""Removes the embed's image.
429+
430+
This function returns the class instance to allow for fluent-style
431+
chaining.
432+
433+
.. versionadded:: 2.0
434+
"""
435+
try:
436+
del self._image
437+
except AttributeError:
438+
pass
439+
440+
return self
441+
442+
427443
@property
428444
def thumbnail(self) -> _EmbedMediaProxy:
429445
"""Returns an ``EmbedProxy`` denoting the thumbnail contents.
@@ -466,6 +482,21 @@ def set_thumbnail(self: E, *, url: MaybeEmpty[Any]) -> E:
466482

467483
return self
468484

485+
def remove_thumbnail(self: E) -> E:
486+
"""Removes the embed's thumbnail.
487+
488+
This function returns the class instance to allow for fluent-style
489+
chaining.
490+
491+
.. versionadded:: 2.0
492+
"""
493+
try:
494+
del self._thumbnail
495+
except AttributeError:
496+
pass
497+
498+
return self
499+
469500
@property
470501
def video(self) -> _EmbedVideoProxy:
471502
"""Returns an ``EmbedProxy`` denoting the video contents.

discord/errors.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ def __init__(self, interaction: Interaction):
289289

290290
class ExtensionError(DiscordException):
291291
"""Base exception for extension related errors.
292+
292293
This inherits from :exc:`~discord.DiscordException`.
294+
293295
Attributes
294296
------------
295297
name: :class:`str`
@@ -304,28 +306,33 @@ def __init__(self, message: Optional[str] = None, *args: Any, name: str) -> None
304306

305307
class ExtensionAlreadyLoaded(ExtensionError):
306308
"""An exception raised when an extension has already been loaded.
309+
307310
This inherits from :exc:`ExtensionError`
308311
"""
309312
def __init__(self, name: str) -> None:
310313
super().__init__(f'Extension {name!r} is already loaded.', name=name)
311314

312315
class ExtensionNotLoaded(ExtensionError):
313316
"""An exception raised when an extension was not loaded.
317+
314318
This inherits from :exc:`ExtensionError`
315319
"""
316320
def __init__(self, name: str) -> None:
317321
super().__init__(f'Extension {name!r} has not been loaded.', name=name)
318322

319323
class NoEntryPointError(ExtensionError):
320324
"""An exception raised when an extension does not have a ``setup`` entry point function.
325+
321326
This inherits from :exc:`ExtensionError`
322327
"""
323328
def __init__(self, name: str) -> None:
324329
super().__init__(f"Extension {name!r} has no 'setup' function.", name=name)
325330

326331
class ExtensionFailed(ExtensionError):
327332
"""An exception raised when an extension failed to load during execution of the module or ``setup`` entry point.
333+
328334
This inherits from :exc:`ExtensionError`
335+
329336
Attributes
330337
-----------
331338
name: :class:`str`
@@ -341,14 +348,17 @@ def __init__(self, name: str, original: Exception) -> None:
341348

342349
class ExtensionNotFound(ExtensionError):
343350
"""An exception raised when an extension is not found.
351+
344352
This inherits from :exc:`ExtensionError`
353+
345354
.. versionchanged:: 1.3
346355
Made the ``original`` attribute always None.
356+
347357
Attributes
348358
-----------
349359
name: :class:`str`
350360
The extension that had the error.
351361
"""
352362
def __init__(self, name: str) -> None:
353-
msg = f'Extension {name!r} could not be loaded.'
363+
msg = f'Extension {name!r} could not be found.'
354364
super().__init__(msg, name=name)

0 commit comments

Comments
 (0)