DiscordPYComponents 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- discordpycomponents-0.2.2.dist-info/METADATA +195 -0
- discordpycomponents-0.2.2.dist-info/RECORD +11 -0
- discordpycomponents-0.2.2.dist-info/WHEEL +5 -0
- discordpycomponents-0.2.2.dist-info/top_level.txt +1 -0
- py_components/__init__.py +4 -0
- py_components/components.py +26 -0
- py_components/enums.py +5 -0
- py_components/http.py +15 -0
- py_components/registry.py +10 -0
- py_components/ui.py +28 -0
- py_components/view.py +33 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: DiscordPYComponents
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Discord Components V2 for discord.py
|
|
5
|
+
Author: 2gm49
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: aiohttp
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
.----..-. .-. .---. .----. .-. .-..----. .----. .-. .-..----..-. .-. .---. .----.
|
|
11
|
+
| {} }\ \/ / / ___}/ {} \| `.' || {} }/ {} \| `| || {_ | `| |{_ _}{ {__
|
|
12
|
+
| .--' } { \ }\ /| |\ /| || .--' \ /| |\ || {__ | |\ | | | .-._} }
|
|
13
|
+
`-' `--' `---' `----' `-' ` `-'`-' `----' `-' `-'`----'`-' `-' `-' `----'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**py-components** is a lightweight Python library that provides helpers for building Discord Components (Buttons, Select Menus, Action Rows) for use with `discord.py`.
|
|
17
|
+
|
|
18
|
+
It is designed to simplify the creation and handling of Discord UI components while keeping the API clean, minimal, and easy to extend.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Simple Discord Components V2 wrapper
|
|
25
|
+
- Easy-to-use Button, Select Menu, and Action Row builders
|
|
26
|
+
- Async-friendly design
|
|
27
|
+
- Clean and readable API
|
|
28
|
+
- Built to integrate with `discord.py`
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install py-components
|
|
36
|
+
````
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Requirements
|
|
41
|
+
|
|
42
|
+
* Python 3.10+
|
|
43
|
+
* discord.py (latest recommended)
|
|
44
|
+
* aiohttp
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### Creating a Button
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from py_components import Button, ActionRow
|
|
54
|
+
|
|
55
|
+
button = Button(
|
|
56
|
+
label="Click Me",
|
|
57
|
+
style="primary",
|
|
58
|
+
custom_id="click_me_button"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
row = ActionRow(components=[button])
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Handling Interactions
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from py_components import Button
|
|
70
|
+
|
|
71
|
+
button = Button(
|
|
72
|
+
label="Hello",
|
|
73
|
+
style="success",
|
|
74
|
+
custom_id="hello_button"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
async def handle_interaction(interaction):
|
|
78
|
+
await interaction.response.send_message("You clicked the button!")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Components
|
|
84
|
+
|
|
85
|
+
### Buttons
|
|
86
|
+
|
|
87
|
+
Supported styles:
|
|
88
|
+
|
|
89
|
+
* primary
|
|
90
|
+
* secondary
|
|
91
|
+
* success
|
|
92
|
+
* danger
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
Button(
|
|
96
|
+
label="Delete",
|
|
97
|
+
style="danger",
|
|
98
|
+
custom_id="delete_btn"
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### Select Menus
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from py_components import SelectMenu
|
|
108
|
+
|
|
109
|
+
menu = SelectMenu(
|
|
110
|
+
custom_id="menu_example",
|
|
111
|
+
options=[
|
|
112
|
+
{"label": "Option 1", "value": "opt1"},
|
|
113
|
+
{"label": "Option 2", "value": "opt2"}
|
|
114
|
+
]
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### Action Rows
|
|
121
|
+
|
|
122
|
+
Used to group components together.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from py_components import ActionRow
|
|
126
|
+
|
|
127
|
+
row = ActionRow(components=[button, menu])
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Example Usage
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from py_components import Button, ActionRow, SelectMenu
|
|
136
|
+
|
|
137
|
+
button = Button(
|
|
138
|
+
label="Click Me",
|
|
139
|
+
style="primary",
|
|
140
|
+
custom_id="btn_1"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
menu = SelectMenu(
|
|
144
|
+
custom_id="menu_1",
|
|
145
|
+
options=[
|
|
146
|
+
{"label": "Red", "value": "red"},
|
|
147
|
+
{"label": "Blue", "value": "blue"}
|
|
148
|
+
]
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
row = ActionRow(components=[button, menu])
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Roadmap
|
|
157
|
+
|
|
158
|
+
* Modal support
|
|
159
|
+
* Full discord.py integration helpers
|
|
160
|
+
* Prebuilt UI templates
|
|
161
|
+
* Advanced component event handling
|
|
162
|
+
* Stronger typing + validation
|
|
163
|
+
* More Discord component types support
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Project Structure
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
py-components/
|
|
171
|
+
├── py_components/
|
|
172
|
+
│ ├── __init__.py
|
|
173
|
+
│ ├── buttons.py
|
|
174
|
+
│ ├── select.py
|
|
175
|
+
│ └── components.py
|
|
176
|
+
├── README.md
|
|
177
|
+
├── pyproject.toml
|
|
178
|
+
└── LICENSE
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT License
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Notes
|
|
190
|
+
|
|
191
|
+
This library is a helper layer for building Discord UI components more efficiently. It does not replace `discord.py`, but extends it with easier component creation utilities.
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
```
|
|
195
|
+
--
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
py_components/__init__.py,sha256=COIyqErNNmT9aM3ZroJY37IauhfA3L-8rI2EAuD8PxM,127
|
|
2
|
+
py_components/components.py,sha256=C544NpQdckIupA3NH48d9i9XsTzrGC-juGJEZ4CNw-o,573
|
|
3
|
+
py_components/enums.py,sha256=1Awd_7bV08ip_Jv7TzBbJjWd0N3TM9912ZvCnVUorHw,84
|
|
4
|
+
py_components/http.py,sha256=GWprDj077w9lb3FMxMOn1DgRO31_Xk7eCqOBhmEKlFA,428
|
|
5
|
+
py_components/registry.py,sha256=LPj-6MPezlpSNJTPN2fdTm7NsDyPwjS45BvUhu4_UGo,275
|
|
6
|
+
py_components/ui.py,sha256=IitDYdlAsAxDktXLQ7qpvPVbXMBzavzYq0YeBMcnXOc,736
|
|
7
|
+
py_components/view.py,sha256=pVLge9W07YmfW-qFwYC5tm30b64Y0pCSC5fBqJVu7RA,734
|
|
8
|
+
discordpycomponents-0.2.2.dist-info/METADATA,sha256=3CO1g1qXfZnvDJ35vQ6_ILPc6U-C61J5y-vtTJ510Mk,3377
|
|
9
|
+
discordpycomponents-0.2.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
10
|
+
discordpycomponents-0.2.2.dist-info/top_level.txt,sha256=Q4JxMCNp7z8AhvKh05KL3isKLp8dycXAvhj74gvjn4w,14
|
|
11
|
+
discordpycomponents-0.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
py_components
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .enums import ButtonStyle
|
|
2
|
+
|
|
3
|
+
class Text:
|
|
4
|
+
def __init__(self, content):
|
|
5
|
+
self.content = content
|
|
6
|
+
|
|
7
|
+
def to_dict(self):
|
|
8
|
+
return {
|
|
9
|
+
"type": 10,
|
|
10
|
+
"content": self.content
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Button:
|
|
15
|
+
def __init__(self, label, custom_id, style=ButtonStyle.primary):
|
|
16
|
+
self.label = label
|
|
17
|
+
self.custom_id = custom_id
|
|
18
|
+
self.style = style
|
|
19
|
+
|
|
20
|
+
def to_dict(self):
|
|
21
|
+
return {
|
|
22
|
+
"type": 2,
|
|
23
|
+
"label": self.label,
|
|
24
|
+
"custom_id": self.custom_id,
|
|
25
|
+
"style": self.style
|
|
26
|
+
}
|
py_components/enums.py
ADDED
py_components/http.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
|
|
3
|
+
API = "https://discord.com/api/v10"
|
|
4
|
+
|
|
5
|
+
async def send_message(channel_id, token, payload):
|
|
6
|
+
url = f"{API}/channels/{channel_id}/messages"
|
|
7
|
+
|
|
8
|
+
headers = {
|
|
9
|
+
"Authorization": f"Bot {token}",
|
|
10
|
+
"Content-Type": "application/json"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async with aiohttp.ClientSession() as session:
|
|
14
|
+
async with session.post(url, json=payload, headers=headers) as resp:
|
|
15
|
+
return await resp.text()
|
py_components/ui.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from .http import send_message
|
|
2
|
+
|
|
3
|
+
class UI:
|
|
4
|
+
def __init__(self, *components):
|
|
5
|
+
self.components = list(components)
|
|
6
|
+
|
|
7
|
+
def add(self, component):
|
|
8
|
+
self.components.append(component)
|
|
9
|
+
|
|
10
|
+
def to_payload(self):
|
|
11
|
+
return {
|
|
12
|
+
"flags": 1 << 15,
|
|
13
|
+
"components": [
|
|
14
|
+
{
|
|
15
|
+
"type": 17,
|
|
16
|
+
"components": [c.to_dict() for c in self.components]
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async def send(self, ctx):
|
|
22
|
+
token = ctx.bot.http.token
|
|
23
|
+
return await send_message(ctx.channel.id, token, self.to_payload())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async def send_ui(ctx, ui):
|
|
27
|
+
token = ctx.bot.http.token
|
|
28
|
+
return await send_message(ctx.channel.id, token, ui.to_payload())
|
py_components/view.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .components import Button
|
|
2
|
+
|
|
3
|
+
def button(label):
|
|
4
|
+
def wrapper(func):
|
|
5
|
+
func._button_label = label
|
|
6
|
+
return func
|
|
7
|
+
return wrapper
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class View:
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self.components = []
|
|
13
|
+
self.registry = {}
|
|
14
|
+
|
|
15
|
+
def add_button(self, label, custom_id, callback=None):
|
|
16
|
+
btn = Button(label, custom_id)
|
|
17
|
+
self.components.append(btn)
|
|
18
|
+
|
|
19
|
+
if callback:
|
|
20
|
+
self.registry[custom_id] = callback
|
|
21
|
+
|
|
22
|
+
return btn
|
|
23
|
+
|
|
24
|
+
def to_payload(self):
|
|
25
|
+
return {
|
|
26
|
+
"flags": 1 << 15,
|
|
27
|
+
"components": [
|
|
28
|
+
{
|
|
29
|
+
"type": 17,
|
|
30
|
+
"components": [c.to_dict() for c in self.components]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|