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

Commit 3e7e5ea

Browse files
author
kuso-senpai
committed
Readme update
1 parent 4714020 commit 3e7e5ea

File tree

4 files changed

+122
-19
lines changed

4 files changed

+122
-19
lines changed

README.md

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ This is a [discord.py](https://github.com/Rapptz/discord.py) button extension ma
77
- [Sending Butttons](#Sending)
88
- [Receiving a button press](#Receiving)
99
- [Complete example](#Example)
10-
- [Code docs](#CodeDocs)
10+
- [Code docs](#Code-docs)
1111
- [Future added](#Future)
1212

1313
- - - -
1414

1515
# Get started
1616

17-
At first, you need a `discord.ext.commands.Bot` client
17+
First things first, the installation for this package
18+
19+
```cmd
20+
py -m pip install discord_py_buttons
21+
```
22+
23+
Then you need a `discord.ext.commands.Bot` client in your code
1824

1925
```py
2026
import discord
2127
from discord.ext import commands
2228

23-
client = commands.Bot()
29+
client = commands.Bot(" ")
2430
```
2531

2632
To initialize the button extension, you need to import the `Buttons` class
@@ -38,7 +44,7 @@ This will add a listener to button presses and will grant you acces to the butto
3844

3945
# Events
4046

41-
These events can be received trought `client.listen('eventName')`
47+
These events can be received trought `client.listen('eventName')` or can be awaited with `client.wait_for('eventName', filter)`
4248

4349
<details>
4450
<summary>on_button_press</summary>
@@ -50,17 +56,21 @@ The parameters passed to your function will be
5056
- `PressedButton`
5157
> The Button which was pressed
5258
53-
5459
- `Message`
5560
> The message on which the button was pressed
5661
57-
Your function should look something like this
62+
If you want to listen to it, your function should look something like this
5863
```py
5964
@client.listen('on_button_press')
6065
async def on_button(btn: PressedButton, message: ResponseMessage)
6166
# code goes here
6267
```
6368

69+
If you want to await this event, use
70+
```py
71+
btn, msg = await client.wait_for('on_button_press', lambda btn, msg: check here)
72+
```
73+
6474
</details>
6575

6676
- - - -
@@ -76,7 +86,7 @@ from discord_py_buttons import Button
7686
@client.listen('on_message')
7787
async def on_message(message: discord.Message):
7888
if message.content == "!btn":
79-
client.buttons.send(message.channel, "here you go", buttons=[Button("myID", "Press me", emoji="😀")])
89+
await client.buttons.send(message.channel, "here you go", buttons=[Button("myID", "Press me", emoji="😀")])
8090
```
8191

8292
- - - -
@@ -119,7 +129,7 @@ client.buttons = Buttons(client)
119129
@client.listen('on_message')
120130
async def on_message(message: discord.Message):
121131
if message.content == "!btn":
122-
client.buttons.send("Here ya go!", buttons=[Button("custom_id", "PRESS ME")])
132+
await client.buttons.send("Here ya go!", buttons=[Button("custom_id", "PRESS ME")])
123133

124134
@client.listen('on_button_press')
125135
async def on_button(btn: PressedButton, msg: ResponseMessage):
@@ -128,13 +138,38 @@ async def on_button(btn: PressedButton, msg: ResponseMessage):
128138
client.run("Your secret token")
129139
```
130140

141+
Here is another example code which uses `client.wait_for`
142+
It will send a question in which the message author decides if they like cats or dogs more
143+
144+
Example
145+
```py
146+
import discord
147+
from discord.ext import commands
148+
from discord_py_buttons import Button, Buttons
149+
150+
client = commands.Bot(" ")
151+
152+
@client.listen('on_message')
153+
async def on_message(message: discord.Message):
154+
if message.content == "!q":
155+
# This will send the buttons to the textchannel
156+
question = await client.buttons.send(message.channel, "What do you like the most?", buttons=[Button("cats", label="I like cats", emoji="🐱"), Button("dogs", label="I like dogs", emoji="🐶")])
157+
# This will wait for a new button press and only continue if the user who pressed the button is the message author and the messageID on which the button was pressed is the same ID as the message we sent (question)
158+
btn, msg = await client.wait_for("button_press", check=lambda btn, msg: btn.member.id == message.author.id and msg.id == question.id)
159+
160+
if btn.custom_id == "cats":
161+
msg.respond("yay, cats!")
162+
elif btn.custom_id == "dogs":
163+
msg.respond("yay, dogs")
164+
```
165+
131166
- - - -
132167

133168
- - - -
134169

135170
- - - -
136171

137-
# CodeDocs
172+
# Code docs
138173

139174

140175
## Buttons: `class`
@@ -305,6 +340,7 @@ This type of button will not trigger the `on_button_press` event
305340

306341
<details>
307342
<summary><b>Initialization</b></summary>
343+
308344
```py
309345
LinkButton(url: str, label: str, emoji: discord.Emoji or str, new_line: bool, disabled: bool)
310346
```
@@ -350,8 +386,10 @@ LinkButton(url: str, label: str, emoji: discord.Emoji or str, new_line: bool, di
350386
351387
- disabled: `bool`
352388
> Whether the button is disabled
389+
353390
</details>
354391

392+
355393
<details>
356394
<summary><b>Methods</b></summary>
357395

@@ -368,7 +406,54 @@ LinkButton(url: str, label: str, emoji: discord.Emoji or str, new_line: bool, di
368406

369407
- - - -
370408

371-
## <a name="Message"></a> Message: `class`
409+
## PressedButton: `class`
410+
411+
Represents an Object of a Button which was pressed, including its interaction
412+
413+
<details>
414+
<summary><b>Attributes</b></summary>
415+
416+
- member: `discord.GuildMember`
417+
> The member who pressed the button
418+
419+
- interaction: `dict`
420+
> The most important stuff for the interaction which was received
421+
422+
<details>
423+
<summary>Values</summary>
424+
425+
- id: `str`
426+
> The interaction ID
427+
- token: `str`
428+
> The interaction token
429+
430+
</details>
431+
432+
- content: `str`
433+
> The content of the button (emoji + " " + label)
434+
435+
- url: `str`
436+
> The link which will be opened when clicking the button
437+
438+
- label: `str`
439+
> The text that appears on the button, max _80_ characters
440+
441+
- color: `str or int`
442+
> The color of the button
443+
>
444+
> This will always be `5` (_linkButton_)
445+
446+
- emoji: `discord.Emoji or str`
447+
> The emoji appearing before the label
448+
449+
- new_line: `bool`
450+
> Whether a new line was added before the button
451+
452+
</details>
453+
454+
- - - -
455+
456+
## Message: `class`
372457

373458
Extends the `discord.Message` object
374459

@@ -481,9 +566,27 @@ Extends the `Message` object
481566

482567
- - - -
483568

484-
<details>
485-
<summary>To-Do</summary>
569+
## Events
570+
571+
Added events for `client.wait_for` and `client.listen`
572+
573+
- <details>
574+
<summary>on_button_press</summary>
575+
576+
```py
577+
(async) def listen(btn: PressedButton, msg: ResponseMessage):
578+
```
579+
580+
This event will be dispatched whenever a button was pressed
581+
582+
Two parameters are passed to the listening function
583+
584+
[`PressedButton`](##-pressed-class)
585+
> The button which was pressed
586+
587+
[`ResponseMessage`](##-responsemessage-class)
588+
> The message with the interaction on which the button was pressed
589+
590+
</details>
486591

487-
- [ ] file sending complete support
488-
- [x] inline => new_line
489-
</details>
592+
add hash value

discord_py_buttons/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from .buttons import Button, LinkButton, Colors
33
from .receive import ResponseMessage, Message, PressedButton
44

5-
__version__ = "1.0.1"
5+
__version__ = "1.0.2"

discord_py_buttons/receive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ 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
3432
"""
3533
def __init__(self, data, user, b: Button) -> None:
3634
bDict = b.to_dict()
@@ -41,6 +39,8 @@ def __init__(self, data, user, b: Button) -> None:
4139
}
4240
self.member: discord.Member = user
4341

42+
del self.disabled
43+
4444
async def getResponseMessage(client: commands.Bot, data, user = None, response = True):
4545
"""
4646
Async function to get the Response Message

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def getReadme():
1313
name="discord-py-buttons",
1414
version=getVersion(),
1515
author="404kuso, RedstoneZockt, ",
16-
16+
1717
description="A discord button handler for discord.py",
1818
long_description=getReadme(),
1919
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)