Skip to content

Commit eeafc56

Browse files
authored
chore: reflect unstable additions to stable. (#449)
chore: reflect unstable additions to stable.
2 parents c539da7 + 50b0f15 commit eeafc56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4736
-801
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.egg-info/
44
*.eggs/
55
*.pyc
6+
.idea
67
.cache/
78
_build/
89
build/
@@ -11,5 +12,5 @@ dist/
1112
.venv
1213
.vscode
1314
__pycache__
14-
1515
*.token
16+
*.pypirc

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.1.0
44
hooks:
55
- id: requirements-txt-fixer
66
name: Requirements
@@ -39,7 +39,7 @@ repos:
3939
name: flake8 Formatting
4040
language: python
4141
types: [file, python]
42-
args: [--max-line-length=100, --ignore=E203 E501 E402 W503 W504]
42+
args: [--max-line-length=100, --ignore=E203 E301 E302 E501 E402 E704 W503 W504]
4343
- repo: https://github.com/pycqa/isort
4444
rev: 5.10.1
4545
hooks:

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ the library off of pip:
1010

1111
.. code-block:: bash
1212
13-
pip install -U discord-py-interactions
13+
pip install -U discord-py-interactions[dev]
1414
1515
Once you have the library installed in Python, you are able to instantiate and run a basic bot
1616
with a logging level that is set for debugging purposes. This is recommend in order to make it easier

LICENSE

Lines changed: 674 additions & 21 deletions
Large diffs are not rendered by default.

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Ever since December 2019, this open-source project has become the culmination of
3636
- Looking for a compatible library that implements all interactions?
3737
- Itching to get your hands on slash commands, but in a simple manner?
3838

39-
Look no more! The goal of this library is to make all three of these questions go from possibilites to trivial matters.
39+
Look no more! The goal of this library is to make all three of these questions go from possibilities to trivial matters.
4040

4141
What can we do?
4242
***************

docs/faq.rst

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,48 @@ What does that mean? Well, we'll show you:
4848
import interactions
4949
from discord.ext import commands
5050
51-
interactions = interactions.Client(token="...")
51+
client = interactions.Client(token="...")
5252
dpy = commands.Bot(prefix="/")
5353
5454
@dpy.command()
5555
async def hello(ctx):
5656
await ctx.send("Hello from discord.py!")
5757
58-
@interactions.command(
58+
@client.command(
5959
name="test",
6060
description="this is just a testing command."
6161
)
6262
async def test(ctx):
6363
await ctx.send("Hello from discord-interactions!")
6464
65-
interactions.start()
66-
dpy.run(token="...", bot=True)
65+
loop = asyncio.get_event_loop()
66+
67+
task2 = loop.create_task(dpy.start(token="...", bot=True))
68+
task1 = loop.create_task(client.ready())
69+
70+
gathered = asyncio.gather(task1, task2, loop=loop)
71+
loop.run_until_complete(gathered)
6772
6873
Both of these variables ``interactions`` and ``dpy`` will be able to run in the same established environment, and additionally
69-
will both function properly as their respective libraries intend them to. What about the models, though? That's a simple answer:
74+
will both function properly as their respective libraries intend them to. This implementation uses asyncio.gather to execute
75+
both starts simultaneously as asyncio tasks, and runs them under one singular loop.
76+
77+
Compared to traditional startup commands, ``interactions.ready()`` and ``dpy.start()`` is used instead of
78+
the typical ``interactions.start()`` and ``dpy.run()`` methods because of synchronous/async functions.
79+
``asyncio.gather()`` works with coroutines, hence the transition.
80+
81+
What about the models, though? That's a simple answer:
7082

7183
.. code-block:: python
7284
7385
import discord
74-
from interactions.api.models.member import Member
86+
import interactions
7587
7688
@dpy.command()
77-
async def borrowing(ctx, member: Member):
89+
async def borrowing(ctx, member: interactions.Member):
7890
await ctx.send(f"Member ID: {member.id}")
7991
80-
@interactions.command(...)
92+
@client.command(...)
8193
async def second_borrowing(ctx, member: discord.Member):
8294
await ctx.send(f"Member ID: {member.id}")
8395
@@ -127,6 +139,26 @@ of discord.py bot developers frown upon doing, so this is at your own risk to co
127139
can take a page out of discord.js' book if you want to do this, since they've never heard of an external command handler framework
128140
before in their entire life.
129141

142+
143+
I'm getting "``AttributeError: HTTPClient not found!``" when I try to execute helper methods!
144+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145+
Probably you are doing something like this:
146+
147+
.. code-block:: python
148+
149+
channel = interactions.Channel(**await bot.http.get_channel(channel_id))
150+
await channel.send("...")
151+
152+
And the error occurs in the line where you try to send something. You can fix this easy by adding one argument:
153+
154+
.. code-block:: python
155+
156+
channel = interactions.Channel(**await bot.http.get_channel(channel_id), _client=bot.http)
157+
await channel.send("...")
158+
159+
You have to add this extra argument for every object you instantiate by yourself if you want to use it's methods
160+
161+
130162
My question is not answered on here!
131163
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132164
Please join our Discord server for any further support regarding our library and/or any integration code depending on it.

interactions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
Co-authored by DeltaXW.
1313
"""
1414
from .api.models.channel import * # noqa: F401 F403
15+
from .api.models.flags import * # noqa: F401 F403
1516
from .api.models.guild import * # noqa: F401 F403
1617
from .api.models.gw import * # noqa: F401 F403
17-
from .api.models.intents import * # noqa: F401 F403
1818
from .api.models.member import * # noqa: F401 F403
1919
from .api.models.message import * # noqa: F401 F403
2020
from .api.models.misc import * # noqa: F401 F403

interactions/api/dispatch.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
from asyncio import get_event_loop
2-
from logging import Logger, StreamHandler, basicConfig, getLogger
2+
from logging import Logger
33
from typing import Coroutine, Optional
44

5-
from ..base import CustomFormatter, Data
5+
from interactions.base import get_logger
66

7-
basicConfig(level=Data.LOGGER)
8-
log: Logger = getLogger("dispatch")
9-
stream: StreamHandler = StreamHandler()
10-
stream.setLevel(Data.LOGGER)
11-
stream.setFormatter(CustomFormatter())
12-
log.addHandler(stream)
7+
log: Logger = get_logger("dispatch")
138

149

1510
class Listener:

interactions/api/error.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class InteractionException(Exception):
2424
and for extensive testing/review before integration.
2525
Likewise, this will show the concepts before use, and will be refined when time goes on.
2626
27-
:ivar interactions.api.error.ErrorFormatter _formatter: The built in formatter.
27+
:ivar interactions.api.error.ErrorFormatter _formatter: The built-in formatter.
2828
:ivar dict _lookup: A dictionary containing the values from the built-in Enum.
2929
3030
"""
@@ -145,7 +145,7 @@ class GatewayException(InteractionException):
145145
"""
146146
This is a derivation of InteractionException in that this is used to represent Gateway closing OP codes.
147147
148-
:ivar ErrorFormatter _formatter: The built in formatter.
148+
:ivar ErrorFormatter _formatter: The built-in formatter.
149149
:ivar dict _lookup: A dictionary containing the values from the built-in Enum.
150150
"""
151151

@@ -178,7 +178,7 @@ class HTTPException(InteractionException):
178178
"""
179179
This is a derivation of InteractionException in that this is used to represent HTTP Exceptions.
180180
181-
:ivar ErrorFormatter _formatter: The built in formatter.
181+
:ivar ErrorFormatter _formatter: The built-in formatter.
182182
:ivar dict _lookup: A dictionary containing the values from the built-in Enum.
183183
"""
184184

@@ -204,7 +204,7 @@ class JSONException(InteractionException):
204204
"""
205205
This is a derivation of InteractionException in that this is used to represent JSON API Exceptions.
206206
207-
:ivar ErrorFormatter _formatter: The built in formatter.
207+
:ivar ErrorFormatter _formatter: The built-in formatter.
208208
:ivar dict _lookup: A dictionary containing the values from the built-in Enum.
209209
"""
210210

0 commit comments

Comments
 (0)