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

Commit dcfab87

Browse files
author
kuso-senpai
committed
updated readme and examples
1 parent 5e1aa32 commit dcfab87

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def on_message(message: discord.Message):
107107
Button("my_custom_id")
108108
])
109109
try:
110-
btn = await msg.wait_for(client, "button", timeout=20)
110+
btn = await msg.wait_for("button", client, by=message.author, timeout=20)
111111
await btn.respond("you pressed `" + btn.content + "`")
112112
except TimeoutError:
113113
await msg.delete()
@@ -135,14 +135,39 @@ async def on_message(message: discord.Message):
135135
SelectOption("my_other_value", emoji="🤗", description="this is a test too")
136136
], max_values=2)])
137137
try:
138-
sel = await msg.wait_for(client, "select", timeout=20)
138+
sel = await msg.wait_for("select", client, by=message.author, timeout=20)
139139
await sel.respond("you selected `" + str([x.content for x in sel.selected_values]) + "`")
140140
except TimeoutError:
141141
await msg.delete()
142142

143143
client.run("your_token_here")
144144
```
145145

146+
Example for cogs
147+
```py
148+
from discord.ext import commands
149+
from discord_ui import UI
150+
from discord_ui.cogs import slash_cog, subslash_cog, listening_component_cog
151+
152+
bot = commands.Bot(" ")
153+
ui = UI(bot)
154+
155+
class Example(commands.Cog):
156+
def __init__(self, bot):
157+
self.bot = bot
158+
159+
@slash_cog(name="example", guild_ids=[785567635802816595])
160+
async def example(self, ctx):
161+
await ctx.respond("gotchu")
162+
163+
@subslash_cog(base_names="example", name="command"):
164+
async def example_command(sef, ctx):
165+
await ctx.respond("okayy")
166+
167+
bot.add_cog(Example(bot))
168+
bot.run("your token")
169+
```
170+
146171
You can find more (and better) examples [here](https://github.com/discord-py-ui/discord-ui/tree/main/examples)
147172

148173
# Changelog

discord_ui/receive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ async def edit(self, token, **fields):
670670
671671
async def testing(ctx):
672672
msg = await ctx.send("hello hidden world", components=[Button("test")])
673-
btn = await msg.wait_for(client, "button")
673+
btn = await msg.wait_for("button", client)
674674
await btn.message.edit(ctx.token, content="edited", components=None)
675675
676676
"""

examples/calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def test(ctx: SlashedCommand):
4141
while True:
4242
try:
4343
# Wait for a button press with a timeout of 20 seconds
44-
btn = await msg.wait_for(client, "button", timeout=20)
44+
btn = await msg.wait_for("button", client, timeout=20)
4545
# Respond to the button, that it was received
4646
await btn.respond(ninja_mode=True)
4747
# If the button was the equal button

examples/role_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def command(ctx: SlashedCommand):
3939
# Wait for a selection on a select menu with the custom_id
4040
# 'role_picker' by the user who used the slash command,
4141
# with a timeout of 20 seconds
42-
menu = await msg.wait_for(client, "select", timeout=20)
42+
menu = await msg.wait_for("select", client, timeout=20)
4343
# Get all roles in the current guild
4444
roles = await ctx.channel.guild.fetch_roles()
4545
given_roles = []

0 commit comments

Comments
 (0)