Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 1832be7

Browse files
author
kuso-senpai
committed
hash attribute added
1 parent 3e7e5ea commit 1832be7

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ Button(custom_id, label = None, color = None, emoji = None, new_line = False, di
288288
289289
- disabled: `bool`
290290
> Whether the button should be clickable (disabled = False) or not (disabled=True)
291+
291292
</details>
292293

293294
<details>
@@ -313,6 +314,9 @@ Button(custom_id, label = None, color = None, emoji = None, new_line = False, di
313314
314315
- disabled: `bool`
315316
> Whether the button is disabled
317+
318+
- hash: `str`
319+
> The unique hash for the button
316320
</details>
317321

318322
<details>
@@ -359,6 +363,7 @@ LinkButton(url: str, label: str, emoji: discord.Emoji or str, new_line: bool, di
359363
360364
- disabled: `bool`
361365
> Whether the button should be clickable (disabled = False) or not (disabled=True)
366+
362367
</details>
363368

364369
<details>
@@ -387,6 +392,9 @@ LinkButton(url: str, label: str, emoji: discord.Emoji or str, new_line: bool, di
387392
- disabled: `bool`
388393
> Whether the button is disabled
389394
395+
- hash: `str`
396+
> The unique hash for the button
397+
390398
</details>
391399

392400

@@ -449,6 +457,14 @@ Represents an Object of a Button which was pressed, including its interaction
449457
- new_line: `bool`
450458
> Whether a new line was added before the button
451459

460+
- disabled: `bool`
461+
> Whether the button is disabled
462+
>
463+
> Always `True`
464+
465+
- hash: `str`
466+
> The unique hash for the button
467+
452468
</details>
453469

454470
- - - -
@@ -587,6 +603,4 @@ Added events for `client.wait_for` and `client.listen`
587603
[`ResponseMessage`](##-responsemessage-class)
588604
> The message with the interaction on which the button was pressed
589605

590-
</details>
591-
592-
add hash value
606+
</details>

discord_py_buttons/buttons.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Button():
2020
new_line: `bool`
2121
Whether a new line should be added before the button
2222
disabled: `bool`
23-
whether the button is clickable or not
23+
Whether the button is clickable or not
24+
hash: `str`
25+
A unique hash for the button
2426
"""
2527
def __init__(self, custom_id: str, label: str = None, color: str or int = "blurple", emoji: Emoji or str = None, new_line: bool = False, disabled: bool = False) -> None:
2628
"""Creates a new Button Object
@@ -195,6 +197,10 @@ def disabled(self, val):
195197
self._json["disabled"] = bool(val)
196198
else:
197199
self._json |= {"disabled": bool(val)}
200+
201+
@property
202+
def hash(self) -> str:
203+
return self._json.get('hash', None)
198204
#endregion
199205

200206
@classmethod
@@ -224,6 +230,8 @@ class LinkButton():
224230
Whether a new line should be added before the button
225231
disabled: `bool`
226232
whether the button is clickable or not
233+
hash: `str`
234+
A unique hash for the button
227235
"""
228236
def __init__(self, url: str, label: str = None, emoji: Emoji or str = None, new_line: bool = False, disabled: bool = False) -> None:
229237
"""Creates a new LinkButton Object
@@ -360,6 +368,10 @@ def disabled(self) -> bool:
360368
@disabled.setter
361369
def disabled(self, val):
362370
self._json["disabled"] = val
371+
372+
@property
373+
def hash(self) -> str:
374+
return self._json.get('hash', None)
363375
#endregion
364376

365377
@staticmethod

discord_py_buttons/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async def send(self, channel: discord.TextChannel, content=None, *, tts=False,
138138
raise discord.Forbidden(r, "Got forbidden response")
139139
if r.status_code != 200:
140140
raise Exception(r.text)
141-
141+
142142
msg = await getResponseMessage(self._discord, r.json(), response=False)
143143

144144
if delete_after is not None:

discord_py_buttons/receive.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ class PressedButton(Button):
2929
For the values, take a look at `Colors`
3030
new_line: `bool`
3131
If a new line was added before the button
32+
disabled: `bool`
33+
Whether the button is disabled
34+
hash: `str`
35+
A unique hash for the button
3236
"""
3337
def __init__(self, data, user, b: Button) -> None:
34-
bDict = b.to_dict()
35-
super().__init__(b.custom_id, label=bDict.get("label", None), color=b.color, emoji=bDict.get("emoji", None), new_line=b.new_line, disabled=b.disabled)
38+
self._json = b.to_dict()
3639
self.interaction = {
3740
"token": data["token"],
3841
"id": data["id"]
3942
}
4043
self.member: discord.Member = user
4144

42-
del self.disabled
43-
4445
async def getResponseMessage(client: commands.Bot, data, user = None, response = True):
4546
"""
4647
Async function to get the Response Message
@@ -420,4 +421,4 @@ def respond(self, content=None, *, tts=False, embed = None, embeds=None, file=No
420421
if r.status_code == 403:
421422
raise discord.Forbidden(r, "Forbidden")
422423
if r.status_code == 400:
423-
raise discord.HTTPException(r, "Error while sending message")
424+
raise discord.ClientException(r.json(), "Error while sending message")

0 commit comments

Comments
 (0)