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

Commit d018a9e

Browse files
committed
updated docs
1 parent 79dbd04 commit d018a9e

File tree

9 files changed

+47
-33
lines changed

9 files changed

+47
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ from discord_ui import UI, SlashOption
6565
client = commands.Bot(" ")
6666
ui = UI(client)
6767

68-
@ui.slash.command("hello_world", options=[SlashOption(bool, "cool", "whether this libary is cool", required=False)], guild_ids=["785567635802816595"])
68+
@ui.slash.command("hello_world", options=[SlashOption(bool, "cool", "whether this libary is cool", required=False)], guild_ids=[785567635802816595])
6969
async def command(ctx, cool=True):
7070
"""This is a simple slash command"""
7171
# you can use docstrings for the slash command description too
@@ -83,7 +83,7 @@ from discurd_ui import UI
8383
client = commands.Bot(" ")
8484
ui = UI(client)
8585

86-
@ui.slash.user_command("avatar", guild_ids=["785567635802816595"])
86+
@ui.slash.user_command("avatar", guild_ids=[785567635802816595])
8787
async def avatar(ctx, user: discord.Member):
8888
"""Sends the avatar of a user"""
8989
await ctx.respond(embed=discord.Embed(description=user.display_name).set_image(url=user.avatar_url))

discord_ui/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,9 @@ def command(self, name=MISSING, description=MISSING, options=[], guild_ids=MISSI
816816
@slash.command(name="hello_world", description="This is a test command",
817817
options=[
818818
SlashOption(str, name="parameter", description="this is a parameter", choices=[{ "name": "choice 1", "value": "test" }])
819-
], guild_ids=["785567635802816595"], default_permission=False,
819+
], guild_ids=[785567635802816595], default_permission=False,
820820
guild_permissions={
821-
"785567635802816595": SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
821+
785567635802816595: SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
822822
}
823823
)
824824
async def command(ctx, parameter = None):
@@ -902,7 +902,7 @@ def subcommand(self, base_names, name=MISSING, description=MISSING, options=[],
902902
903903
@slash.subcommand_group(base_names="hello", name="world", options=[
904904
SlashOption(argument_type="user", name="user", description="the user to tell the holy words")
905-
], guild_ids=["785567635802816595"])
905+
], guild_ids=[785567635802816595])
906906
async def command(ctx, user):
907907
...
908908
@@ -912,7 +912,7 @@ async def command(ctx, user):
912912
913913
@slash.subcommand_group(base_names=["hello", "beautiful"], name="world", options=[
914914
SlashOption(argument_type="user", name="user", description="the user to tell the holy words")
915-
], guild_ids=["785567635802816595"])
915+
], guild_ids=[785567635802816595])
916916
async def command(ctx, user):
917917
...
918918
@@ -985,8 +985,8 @@ def user_command(self, name=MISSING, guild_ids=MISSING, default_permission=True,
985985
986986
.. code-block::
987987
988-
@slash.user_command(name="call", guild_ids=["785567635802816595"], default_permission=False, guild_permissions={
989-
"785567635802816595": SlashPermission(allowed={
988+
@slash.user_command(name="call", guild_ids=[785567635802816595], default_permission=False, guild_permissions={
989+
785567635802816595: SlashPermission(allowed={
990990
"585567635802816595": SlashPermission.USER
991991
})
992992
})
@@ -1031,8 +1031,8 @@ def message_command(self, name=MISSING, guild_ids=MISSING, default_permission=Tr
10311031
10321032
.. code-block::
10331033
1034-
@slash.message_command(name="quote", guild_ids=["785567635802816595"], default_permission=False, guild_permissions={
1035-
"785567635802816595": SlashPermission(allowed={
1034+
@slash.message_command(name="quote", guild_ids=[785567635802816595], default_permission=False, guild_permissions={
1035+
785567635802816595: SlashPermission(allowed={
10361036
"585567635802816595": SlashPermission.USER
10371037
})
10381038
})

discord_ui/cogs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ class My_Cog(commands.Cog)
352352
353353
@slash_cog(name="hello_world", options=[
354354
SlashOption(str, name="parameter", description="this is a parameter", choices=[{ "name": "choice 1", "value": "test" }])
355-
], guild_ids=["785567635802816595"], default_permission=False,
355+
], guild_ids=[785567635802816595], default_permission=False,
356356
guild_permissions={
357-
"785567635802816595": SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
357+
785567635802816595: SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
358358
}
359359
)
360360
async def hello_world(self, ctx, parameter = None):
@@ -420,7 +420,7 @@ class My_Cog(commands.Cog):
420420
421421
@subslash_cog(base_names="hello", name="world", options=[
422422
SlashOption(argument_type="user", name="user", description="the user to tell the holy words")
423-
], guild_ids=["785567635802816595"])
423+
], guild_ids=[785567635802816595])
424424
async def command(ctx, user):
425425
...
426426
@@ -433,7 +433,7 @@ class My_Cog(commands.Cog):
433433
434434
@subslash_cog(base_names=["hello", "beautiful"], name="world", options=[
435435
SlashOption(argument_type="user", name="user", description="the user to tell the holy words")
436-
], guild_ids=["785567635802816595"])
436+
], guild_ids=[785567635802816595])
437437
async def command(ctx, user):
438438
...
439439
@@ -483,7 +483,7 @@ class My_Cog(commands.Cog):
483483
...
484484
485485
# message command
486-
@context_cog(type="message", name="quote", guild_ids=["785567635802816595"])
486+
@context_cog(type="message", name="quote", guild_ids=[785567635802816595])
487487
async def quote(ctx, message):
488488
...
489489

discord_ui/slash/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,9 @@ async def my_function(command, parameter=None):
388388
SlashCommand(callback=my_function, name="hello_world", description="This is a test command",
389389
options=[
390390
SlashOption(str, name="parameter", description="this is a parameter", choices=[{ "name": "choice 1", "value": 1 }])
391-
], guild_ids=["785567635802816595"], default_permission=False,
391+
], guild_ids=[785567635802816595], default_permission=False,
392392
guild_permissions={
393-
"785567635802816595": SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
393+
785567635802816595: SlashPermission(allowed={"539459006847254542": SlashPermission.USER})
394394
})
395395
```
396396
"""

docs/source/usage.rst

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ It acceps a list of :class:`~SlashOption`
307307
308308
@ui.slash.command(name="test", description="this is a test command", options=[
309309
SlashOption(int, name="parameter1", description="this is a parameter")
310-
], guild_ids=["785567635802816595"])
310+
], guild_ids=[785567635802816595])
311311
async def command(ctx, parameter1="nothing"):
312312
await ctx.respond("I got `" + str(parameter1) + "` for `parameter1`")
313313
@@ -344,17 +344,13 @@ If you want the parameter to be required, in the option, you have to set ``requi
344344
345345
@ui.slash.command(name="test", description="this is a test command", options=[
346346
SlashOption(int, name="parameter1", description="this is a parameter", required=True)
347-
], guild_ids=["785567635802816595"])
347+
], guild_ids=[785567635802816595])
348348
async def command(ctx, parameter1):
349349
await ctx.respond("I got `" + str(parameter1) + "` for `parameter1`")
350350
351351
.. image:: images/slash/test_param_options_required.gif
352352
:width: 550
353353

354-
.. note::
355-
356-
the ``parameter`` argument of the callback function doesn't have a default value anymore,
357-
because if the command is used, it will always get a value passed
358354

359355
Choices
360356
~~~~~~~~~~
@@ -370,13 +366,28 @@ Too add them, where we add the options with the :class:`~SlashOption` class, we
370366
SlashOption(int, name="parameter1", description="this is a parameter", choices=[
371367
{"name": "first choice", "value": 1}, {"name": "second choice", "value": 2}
372368
])
373-
], guild_ids=["785567635802816595"])
369+
], guild_ids=[785567635802816595])
374370
async def command(ctx, parameter1="nothing"):
375371
await ctx.respond("I got `" + str(parameter1) + "` for `parameter1`")
376372
377373
Choices are a list of dict, where ``"name":`` is the displayed choice name and ``"value":`` is the real value,
378374
which will be received when the choice is selected
379375

376+
You can also use the ``create_choice`` function to make it easier
377+
378+
.. code-block::
379+
380+
from discord_ui import create_choice
381+
...
382+
383+
@ui.slash.command(name="test", description="this is a test command", options=[
384+
SlashOption(int, name="parameter1", description="this is a parameter", choices=[
385+
create_choice("first choice", 1), create_choice("second choice", 2)
386+
])
387+
], guild_ids=[785567635802816595])
388+
async def command(ctx, parameter1="nothing"):
389+
await ctx.respond("I got `" + str(parameter1) + "` for `parameter1`")
390+
380391
.. image:: images/slash/test_param_choices.gif
381392
:width: 550
382393

@@ -402,7 +413,7 @@ If the default permission to ``False``, no one can use the command, if it's ``Tr
402413
403414
@ui.slash.command(name="test", description="this is a test command", options=[
404415
SlashOption(int, name="parameter1", description="this is a parameter")
405-
], guild_ids=["785567635802816595"], default_permission=False)
416+
], guild_ids=[785567635802816595], default_permission=False)
406417
async def command(ctx, parameter1="nothing"):
407418
...
408419
@@ -420,8 +431,8 @@ You can add role ids or/and user ids
420431
421432
@ui.slash.command(name="test", description="this is a test command", options=[
422433
SlashOption(int, name="parameter1", description="this is a parameter")
423-
], guild_ids=["785567635802816595"], guild_permissions={
424-
"785567635802816595": SlashPermission(
434+
], guild_ids=[785567635802816595], guild_permissions={
435+
785567635802816595: SlashPermission(
425436
allowed={
426437
"539459006847254542": SlashPermission.USER,
427438
"849035012476895232": SlashPermission.ROLE
@@ -444,6 +455,9 @@ Forbidden command
444455
:width: 1000
445456

446457

458+
You can later update the command permissions with the :meth:`~Slash.update_permissions` function.
459+
460+
447461
guild ids
448462
~~~~~~~~~~~
449463

@@ -453,7 +467,7 @@ To set the guilds where the command is useable, you need to set the ``guild_id``
453467

454468
.. code-block::
455469
456-
@ui.slash.command(name="test", description="this is a test command", guild_ids=["785567635802816595"])
470+
@ui.slash.command(name="test", description="this is a test command", guild_ids=[785567635802816595])
457471
async def command(ctx, parameter1="nothing"):
458472
...
459473

examples/calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
# Create a slash command
33-
@ui.slash.command(name="calculator", description="opens a calculator, that will automatically close when no input was provided after 20 seconds", guild_ids=["785567635802816595"])
33+
@ui.slash.command(name="calculator", description="opens a calculator, that will automatically close when no input was provided after 20 seconds", guild_ids=[785567635802816595])
3434
async def test(ctx: SlashedCommand):
3535
# The current query for the calculator
3636
query = ""

examples/context_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
# Create the command
21-
@ui.slash.message_command("quote", ["785567635802816595"])
21+
@ui.slash.message_command("quote", [785567635802816595])
2222
# register the callback
2323
async def quote(ctx, message):
2424
# respond to the interaction so no error will show up
@@ -31,7 +31,7 @@ async def quote(ctx, message):
3131
await webhook.delete()
3232

3333
# Create the command
34-
@ui.slash.user_command("avatar", ["785567635802816595"])
34+
@ui.slash.user_command("avatar", [785567635802816595])
3535
# register the callback
3636
async def avatar(ctx, user):
3737
# send a embed with the user's avatar

examples/generate_linkbutton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
SlashOption(str, "emoji", "a emoji appearing before the text")
2929
],
3030
# If you want to test the command, use guild_ids, because this is way faster than global commands
31-
guild_ids=["785567635802816595"])
31+
guild_ids=[785567635802816595])
3232
async def command(ctx, message_content="cool, right?", name="click me", link="https://github.com/discord-py-ui/discord-ui", emoji=None):
3333
# Check if the link is valid
3434
if not link.startswith("http://") and not link.startswith("https://"):

examples/role_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ui = UI(client, slash_options={"wait_sync": 2, "delete_unused": True})
2323

2424
# Create a slash command
25-
@ui.slash.command(name="role-picker", description="let's you pick roles", guild_ids=["785567635802816595"])
25+
@ui.slash.command(name="role-picker", description="let's you pick roles", guild_ids=[785567635802816595])
2626
async def command(ctx: SlashedCommand):
2727

2828
# The role picker component

0 commit comments

Comments
 (0)