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

Commit 7d386f4

Browse files
committed
updated readme examples
1 parent 30b1dd1 commit 7d386f4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ ui = UI(client)
8888
async def avatar(ctx, user: discord.Member):
8989
"""Sends the avatar of a user"""
9090
await ctx.respond(embed=discord.Embed(description=user.display_name).set_image(url=user.avatar_url))
91+
92+
client.run("your_token")
93+
```
94+
95+
Example for autocompletion of choices
96+
97+
```py
98+
import discord
99+
from discord_ui import UI, SlashOption, ChoiceGeneratorContext
100+
101+
async def generator(ctx: ChoiceGeneratorContext):
102+
available_choices = ["hmm", "this", "is", "a", "an", "test", "testing"]
103+
return [x for x in available_choices if x.startswith(ctx.value_query)]
104+
105+
@ui.slash.command("search_word", options=[SlashOption(str, "query", choice_generator=generator)])
106+
async def search_word(ctx, query):
107+
await ctx.send("got " + query + " for query")
108+
109+
client.run("your_token")
91110
```
92111

93112
Example for sending a button and receiving it
@@ -195,7 +214,7 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
195214
> `choice_generator` keyword and `autocomplete` keyword.
196215
> `autocomplete` is not needed if you pass choice_generator
197216
- File sending
198-
> You are now able to send hidden files
217+
> You are now able to send hidden files
199218
200219
</details>
201220

0 commit comments

Comments
 (0)