Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
661d053
add discord developers server
hackermondev Sep 2, 2021
2414b04
Merge pull request #64 from Pycord-Development/slash
CodeWithSwastik Sep 2, 2021
af4d6ca
Update README.rst
CodeWithSwastik Sep 2, 2021
16dcf2c
Merge pull request #62 from hackermondev/master
Middledot Sep 2, 2021
1c21f64
Make invalid token type raise TypeError
Dorukyum Sep 3, 2021
8824d66
Merge pull request #88 from Dorukyum/master
Dorukyum Sep 4, 2021
7c4b493
Move Extension Errors to discord.errors
Middledot Sep 4, 2021
f261b84
Add extension errors from ext.commands.errors
Middledot Sep 4, 2021
ba46224
Improve message for `ExtensionNotFound`
izxxr Sep 5, 2021
6473607
Add `remove_image` and `remove_thumbnail` methods.
izxxr Sep 5, 2021
60072da
Typehint new methods
izxxr Sep 5, 2021
a574782
Merge pull request #108 from nerdguyahmad/patch-1
Dorukyum Sep 5, 2021
7e8c3e9
Add missing Bot.run() line
izxxr Sep 6, 2021
0df3128
Merge pull request #115 from nerdguyahmad/patch-5
CodeWithSwastik Sep 6, 2021
d119c0d
Use slash_command in examples
CodeWithSwastik Sep 6, 2021
5dbc432
Rephrase comment in example
CodeWithSwastik Sep 6, 2021
8aa1e90
Merge pull request #111 from nerdguyahmad/patch-4
Dorukyum Sep 6, 2021
6d00c95
Fix Components getting added to children instead of Items
Luc1412 Sep 6, 2021
e6bdfeb
Removed redundant type declaration of input_type argument of class Op…
rpop0 Sep 6, 2021
6e8b2fe
Add Color.nitro_pink
izxxr Sep 7, 2021
8e82671
Merge pull request #122 from nerdguyahmad/patch-6
Dorukyum Sep 7, 2021
eb49f07
Add basic `RawThreadDeleteEvent`
izxxr Sep 7, 2021
6fdc107
Add missing import & Fix typehint of thread
izxxr Sep 7, 2021
df67106
[types] Add ThreadDeleteEvent to raw models
izxxr Sep 7, 2021
337ca55
Remove usage of .get() and typehint data.
izxxr Sep 7, 2021
ce87a0d
Dispatch `raw_thread_delete`
izxxr Sep 7, 2021
5ee36c6
Document raw_thread_delete event
izxxr Sep 7, 2021
da64868
Add archived thread notice and document RawThreadDeleteEvent
izxxr Sep 7, 2021
f13d9f2
Typecast IDs and add __slots__
izxxr Sep 7, 2021
f8d3153
Add Thread import
izxxr Sep 7, 2021
5388f50
Merge pull request #121 from rpop0/slash_command_option_input_type_fix
CodeWithSwastik Sep 7, 2021
5fd13c6
Remove type hinting of slash_command, user_command, message_command
rpop0 Sep 7, 2021
cff98c5
Merge pull request #125 from rpop0/slash_command_not_callabe_fix
CodeWithSwastik Sep 7, 2021
3b406b3
Add create_party_invite shortcut method
CodeWithSwastik Sep 7, 2021
c42fcef
Merge branch 'Pycord-Development:master' into master
Luc1412 Sep 7, 2021
1a79a9c
Merge pull request #119 from Luc1412/master
BobDotCom Sep 7, 2021
2a46b88
Change create_party_invite to create_activity_invite
CodeWithSwastik Sep 8, 2021
5da5516
Make InteractionContext an abc.Messageable
BobDotCom Sep 8, 2021
b1af10a
add abc.messageable to __all__
BobDotCom Sep 8, 2021
f412916
remove interactioncontext.typing
BobDotCom Sep 8, 2021
f7378fb
Merge pull request #128 from CodeWithSwastik/master
CodeWithSwastik Sep 8, 2021
cc4381b
Update colour.py
proguy914629bot Sep 8, 2021
1009a8d
Update colour.py
proguy914629bot Sep 8, 2021
b55fb12
Update colour.py
proguy914629bot Sep 8, 2021
049945c
Merge pull request #132 from LyricMaster-Bot/master
Middledot Sep 8, 2021
1170ad5
Allow option decor to infer type from the typehint
Grace-codes Sep 9, 2021
6ec3d56
Merge pull request #139 from Grace-codes/patch-1
CodeWithSwastik Sep 9, 2021
fe31e46
Merge pull request #123 from nerdguyahmad/raw-thread-delete
CodeWithSwastik Sep 9, 2021
5a727fa
[welcome_screen] basic implementation
izxxr Sep 9, 2021
5dd2ab3
[welcome_screen] Add relative import for welcome_screen
izxxr Sep 9, 2021
d874769
[guild] Add support for getting welcome screen
izxxr Sep 9, 2021
74b8cd2
Fixed potentjal NameErrors and AttributeErrors
izxxr Sep 9, 2021
a437e1c
Add support for editing welcome screen
izxxr Sep 9, 2021
c78b0d3
Fix NameError
izxxr Sep 9, 2021
5e35253
Add shorthand for WelcomeScreen.edit()
izxxr Sep 9, 2021
5c28ce9
fix: typo
izxxr Sep 9, 2021
b60ff11
Return updated instances on edit
izxxr Sep 9, 2021
996c0f8
Typehint WelcomeScreen
izxxr Sep 9, 2021
e3e0e14
Document welcome screen
izxxr Sep 9, 2021
6439c2f
Add NotFound detail
izxxr Sep 9, 2021
310c095
Make get_or_fetch return None instead of raising Exception
CodeWithSwastik Sep 9, 2021
e5099e1
Fix incorrect error
CodeWithSwastik Sep 9, 2021
b1faa17
Merge pull request #143 from nerdguyahmad/welcome-screen
CodeWithSwastik Sep 9, 2021
5d4e7a2
Update CONTRIBUTING.md
BobDotCom Sep 9, 2021
8725ad1
Merge branch 'slash' into context
BobDotCom Sep 9, 2021
7bf8ff6
change InteractionContext to ApplicationContext
BobDotCom Sep 9, 2021
32f2929
Merge pull request #130 from Pycord-Development/context
BobDotCom Sep 9, 2021
fe4ee70
Merge branch 'master' into slash
BobDotCom Sep 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ If the bug report is missing this information then it'll take us longer to fix t

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.

### Licensing

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.

### Git Commit Guidelines

- Use present tense (e.g. "Add feature" not "Added feature")
Expand Down
29 changes: 14 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,20 @@ Quick Example

import discord

class MyClient(discord.Client):
async def on_ready(self):
print("Logged on as", self.user)

async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return

if message.content == "ping":
await message.channel.send("pong")

client = MyClient()
client.run("token")
bot = discord.Bot()

@bot.slash_command()
async def hello(ctx, name: str = None):
name = name or ctx.author.name
await ctx.send(f"Hello {name}!")

@bot.user_command(name="Say Hello")
async def hi(ctx, user):
await ctx.send(f"{ctx.author.mention} says hello to {user.name}!")

bot.run("token")

Bot Example
Normal Commands Example
~~~~~~~~~~~~~

.. code:: py
Expand All @@ -110,4 +108,5 @@ Links

- `Documentation <https://pycord.readthedocs.io/en/latest/index.html>`_
- `Official Discord Server <https://discord.gg/dK2qkEJ37N>`_
- `Discord Developers <https://discord.gg/discord-developers>`_
- `Discord API <https://discord.gg/discord-api>`_
2 changes: 2 additions & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
from .bot import *
from .app import *
from .cog import Cog
from .welcome_screen import *


class VersionInfo(NamedTuple):
major: int
Expand Down
4 changes: 3 additions & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'GuildChannel',
'Messageable',
'Connectable',
'Mentionable'
)

T = TypeVar('T', bound=VoiceProtocol)
Expand Down Expand Up @@ -1141,6 +1142,7 @@ class Messageable:
- :class:`~discord.Member`
- :class:`~discord.ext.commands.Context`
- :class:`~discord.Thread`
- :class:`~discord.ApplicationContext`
"""

__slots__ = ()
Expand Down Expand Up @@ -1690,4 +1692,4 @@ async def connect(

class Mentionable:
# TODO: documentation, methods if needed
pass
pass
16 changes: 9 additions & 7 deletions discord/app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
<= SlashCommandOptionType.role.value
):
name = "member" if op.input_type.name == "user" else op.input_type.name
arg = await get_or_fetch(ctx.guild, name, int(arg))
arg = await get_or_fetch(ctx.guild, name, int(arg), default=int(arg))

elif op.input_type == SlashCommandOptionType.mentionable:
try:
arg = await get_or_fetch(ctx.guild, "member", int(arg))
except NotFound:
arg = await get_or_fetch(ctx.guild, "role", int(arg))
arg_id = int(arg)
arg = await get_or_fetch(ctx.guild, "member", arg_id)
if arg is None:
arg = ctx.guild.get_role(arg_id) or arg_id

kwargs[op.name] = arg

Expand Down Expand Up @@ -466,7 +466,7 @@ def _update_copy(self, kwargs: Dict[str, Any]):

class Option:
def __init__(
self, input_type: Any, /, description = None,**kwargs
self, input_type: Any, /, description: str = None, **kwargs
) -> None:
self.name: Optional[str] = kwargs.pop("name", None)
self.description = description or "No description provided"
Expand Down Expand Up @@ -501,9 +501,11 @@ def __init__(self, name: str, value: Optional[Union[str, int, float]] = None):
def to_dict(self) -> Dict[str, Union[str, int, float]]:
return {"name": self.name, "value": self.value}

def option(name, type, **kwargs):
def option(name, type=None, **kwargs):
"""A decorator that can be used instead of typehinting Option"""
def decor(func):
nonlocal type
type = type or func.__annotations__.get(name, str)
func.__annotations__[name] = Option(type, **kwargs)
return func
return decor
Expand Down
18 changes: 8 additions & 10 deletions discord/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@

from typing import TYPE_CHECKING, Optional, Union

import discord.abc

if TYPE_CHECKING:
import discord
from discord.state import ConnectionState

from ..guild import Guild
from ..interactions import Interaction, InteractionResponse
from ..member import Member
from ..message import Message
from ..user import User
from ..utils import cached_property
from ..context_managers import Typing


class ApplicationContext:
class ApplicationContext(discord.abc.Messageable):
"""Represents a Discord interaction context.

This class is not created manually and is instead passed to application
Expand All @@ -58,6 +60,10 @@ def __init__(self, bot: "discord.Bot", interaction: Interaction):
self.bot = bot
self.interaction = interaction
self.command = None
self._state: ConnectionState = self.interaction._state

async def _get_channel(self) -> discord.abc.Messageable:
return self.channel

@cached_property
def channel(self):
Expand Down Expand Up @@ -87,9 +93,6 @@ def user(self) -> Optional[Union[Member, User]]:
def voice_client(self):
return self.guild.voice_client

def typing(self):
return Typing(self.channel)

@cached_property
def response(self) -> InteractionResponse:
return self.interaction.response
Expand All @@ -100,11 +103,6 @@ def response(self) -> InteractionResponse:
def respond(self):
return self.followup.send if self.response.is_done() else self.interaction.response.send_message

@property
def send(self):
"""Behaves like :attr:`~discord.abc.Messagable.send` if the response is done, else behaves like :attr:`~discord.app.ApplicationContext.respond`"""
return self.channel.send if self.response.is_done() else self.respond

@property
def defer(self):
return self.interaction.response.defer
Expand Down
6 changes: 3 additions & 3 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async def process_application_commands(self, interaction: Interaction) -> None:
else:
self.dispatch('application_command_completion', ctx)

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

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

def message_command(self, **kwargs) -> MessageCommand:
def message_command(self, **kwargs):
"""A shortcut decorator that invokes :func:`.ApplicationCommandMixin.command` and adds it to
the internal command list via :meth:`~.ApplicationCommandMixin.add_application_command`.
This shortcut is made specifically for :class:`.MessageCommand`.
Expand Down
61 changes: 60 additions & 1 deletion discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

import discord.abc
from .permissions import PermissionOverwrite, Permissions
from .enums import ChannelType, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode
from .enums import ChannelType, InviteTarget, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode
from .mixins import Hashable
from .object import Object
from . import utils
Expand All @@ -55,6 +55,7 @@
from .stage_instance import StageInstance
from .threads import Thread
from .iterators import ArchivedThreadIterator
from .invite import Invite

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

async def create_activity_invite(self, event:str, **kwargs) -> Invite:
"""|coro|

A shortcut method that creates an instant activity invite.

You must have the :attr:`~discord.Permissions.create_instant_invite` permission to
do this.

Parameters
------------
event: :class:`str`
The event to create an invite for.
max_age: :class:`int`
How long the invite should last in seconds. If it's 0 then the invite
doesn't expire. Defaults to ``0``.
max_uses: :class:`int`
How many uses the invite could be used for. If it's 0 then there
are unlimited uses. Defaults to ``0``.
temporary: :class:`bool`
Denotes that the invite grants temporary membership
(i.e. they get kicked after they disconnect). Defaults to ``False``.
unique: :class:`bool`
Indicates if a unique invite URL should be created. Defaults to True.
If this is set to ``False`` then it will return a previously created
invite.
reason: Optional[:class:`str`]
The reason for creating this invite. Shows up on the audit log.


Raises
-------
InvalidArgument
If the event is not a valid event.
~discord.HTTPException
Invite creation failed.

Returns
--------
:class:`~discord.Invite`
The invite that was created.
"""

application_ids = {
'youtube' : 755600276941176913,
'poker' : 755827207812677713,
'betrayal': 773336526917861400,
'fishing' : 814288819477020702,
'chess' : 832012774040141894,
}
event = application_ids.get(event)
if event is None:
raise InvalidArgument('Invalid event.')

return await self.create_invite(
target_type=InviteTarget.embedded_application,
target_application_id=event,
**kwargs
)

class StageChannel(VocalGuildChannel):
"""Represents a Discord guild stage channel.
Expand Down
4 changes: 4 additions & 0 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,17 @@ async def login(self, token: str) -> None:

Raises
------
TypeError
The token was in invalid type.
:exc:`.LoginFailure`
The wrong credentials are passed.
:exc:`.HTTPException`
An unknown HTTP related error occurred,
usually when it isn't 200 or the known incorrect credentials
passing status code.
"""
if not isinstance(token, str):
raise TypeError(f"token must be of type str, not {token.__class__.__name__}")

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

Expand Down
8 changes: 8 additions & 0 deletions discord/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,13 @@ def yellow(cls: Type[CT]) -> CT:
"""
return cls(0xFEE75C)

@classmethod
def nitro_pink(cls: Type[CT]) -> CT:
"""A factory method that returns a :class:`Colour` with a value of ``0xf47fff``.

.. versionadded:: 2.0
"""
return cls(0xf47fff)


Color = Colour
31 changes: 31 additions & 0 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,22 @@ def set_image(self: E, *, url: MaybeEmpty[Any]) -> E:

return self

def remove_image(self: E) -> E:
"""Removes the embed's image.

This function returns the class instance to allow for fluent-style
chaining.

.. versionadded:: 2.0
"""
try:
del self._image
except AttributeError:
pass

return self


@property
def thumbnail(self) -> _EmbedMediaProxy:
"""Returns an ``EmbedProxy`` denoting the thumbnail contents.
Expand Down Expand Up @@ -466,6 +482,21 @@ def set_thumbnail(self: E, *, url: MaybeEmpty[Any]) -> E:

return self

def remove_thumbnail(self: E) -> E:
"""Removes the embed's thumbnail.

This function returns the class instance to allow for fluent-style
chaining.

.. versionadded:: 2.0
"""
try:
del self._thumbnail
except AttributeError:
pass

return self

@property
def video(self) -> _EmbedVideoProxy:
"""Returns an ``EmbedProxy`` denoting the video contents.
Expand Down
Loading