Skip to content

Commit

Permalink
fix: correct pre-commit on legacy.
Browse files Browse the repository at this point in the history
  • Loading branch information
i0bs committed Dec 14, 2021
1 parent 63dd9cb commit 50066fc
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/custom---miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ labels: question
assignees: ''

---


Binary file modified .github/banner_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/discordpyslashlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
.cache/
_build/
build/
dist/
dist/
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,3 @@ For more advanced use, please refer to our official documentation on [context me
- [discord-interactions-python](https://github.com/discord/discord-interactions-python)
- If you are looking for a similar library for other languages, please refer to here:
- [discord-api-docs Community Resources: Interactions](https://discord.com/developers/docs/topics/community-resources#interactions)

Binary file modified docs/_static/scope.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Yep we support those too. You use them much the same as buttons. You can only ha
min_values=1, # the minimum number of options a user must select
max_values=2, # the maximum number of options a user can select
)
await ctx.send("test", components=[create_actionrow(select)]) # like action row with buttons but without * in front of the variable
@bot.event
Expand Down
2 changes: 1 addition & 1 deletion docs/discord_slash.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ discord\_slash.model module
:undoc-members:
:show-inheritance:
:inherited-members: Message
:exclude-members: tts, content, channel, webhook_id, mention_everyone, embeds, id, mentions, author, attachments, nonce, pinned, role_mentions, type, call, flags, reactions, reference, application, activity, stickers
:exclude-members: tts, content, channel, webhook_id, mention_everyone, embeds, id, mentions, author, attachments, nonce, pinned, role_mentions, type, call, flags, reactions, reference, application, activity, stickers
2 changes: 1 addition & 1 deletion docs/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ These events can be registered to discord.py's listener or
:param ctx: Context of the callback.
:type ctx: :class:`.model.ComponentContext`
:param ex: Exception from the command invoke.
:type ex: Exception
:type ex: Exception
6 changes: 3 additions & 3 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If you want your commands automatically registered, set ``sync_commands`` to ``T
.. code-block:: python
from discord_slash import SlashCommand
slash = SlashCommand(client, sync_commands=True)
Or, if you want to send requests manually, you can use :class:`.http.SlashCommandRequest`.
Expand Down Expand Up @@ -77,7 +77,7 @@ ctx.channel.send
``ctx.channel`` is the :class:`discord.TextChannel` object for the channel that the slash command was used in.
``send()`` is the sending coroutine in discord.py. (:meth:`discord.TextChannel.send`)

.. warning::
.. warning::
* If the bot is not in the guild, but slash commands are, ``ctx.channel`` will be ``None`` and this won't work.
* If the bot does not have view/send permissions in that channel this also won't work, but slash commands show up no matter what the channel specific permissions.

Expand All @@ -99,7 +99,7 @@ discord.py check decorators can work, but its not 100% guaranteed every checks w
Events
------
Command-related events like ``on_command_error``, ``on_command``, etc.
This extension triggers some events, check the `events docs <https://discord-py-slash-command.readthedocs.io/en/latest/events.html#>`_
This extension triggers some events, check the `events docs <https://discord-py-slash-command.readthedocs.io/en/latest/events.html#>`_

Converters
----------
Expand Down
46 changes: 23 additions & 23 deletions docs/gettingstarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ works:
"name": "test",
"description": "This is just a test command, nothing more.",
}
Now that we have a basic understanding of how the JSON table works, we can
take this knowledge and convert it into a decorator method for the Python
code as shown below:
Expand All @@ -55,7 +55,7 @@ code as shown below:
description="This is just a test command, nothing more.")
async def test(ctx):
await ctx.send(content="Hello World!")
Now that we've gone over how Discord handles the declaration of slash commands
through their Bot API, let's go over what some of the other things mean within
the *logical* part of our code, the command function:
Expand Down Expand Up @@ -139,7 +139,7 @@ The purpose of having the ``ApplicationCommandOptionType`` value passed into our
is so that we can help the Discord UI understand what kind of value we're inputting here. For instance,
if we're wanting to put in a string response, we'll pass the ID 3 so that the UI of Discord chat bar
knows to format it visually this way. If we're looking for a user, then we'll pass ID 6 so that it presents
us with a list of users in our server instead, making it easier on our lives.
us with a list of users in our server instead, making it easier on our lives.

This is not to be confused, however, with formatting the response type itself. This is merely a method so
that the API wrapper can help us with passing the correct type or instance variable with the arguments of the
Expand All @@ -150,7 +150,7 @@ Now, we can finally visualize this by coding an example of this being used in th
.. code-block:: python
from discord_slash.utils.manage_commands import create_option
@slash.slash(name="test",
description="This is just a test command, nothing more.",
options=[
Expand All @@ -163,23 +163,23 @@ Now, we can finally visualize this by coding an example of this being used in th
])
async def test(ctx, optone: str):
await ctx.send(content=f"I got you, you said {optone}!")
Additionally, we could also declare the type of our command's option through this method shown here:

.. code-block:: python
from discord_slash.model import SlashCommandOptionType
(...)
option_type=SlashCommandOptionType.STRING
More in the option? Give them a choice.
---------------------------------------

Alas, there is also a way to give even more information to options with Discord's Slash Commands:
a choice. Not like something that you're given at birth of when you become of legal age as an adult,
we're not here to give you *that* kind of life advice, but the choice of what value you want your
we're not here to give you *that* kind of life advice, but the choice of what value you want your
option to rather pass. Below is a table that shows the JSON structure of how choices are represented
for an option:

Expand All @@ -200,16 +200,16 @@ be designed:
"name": "ChoiceOne",
"value": "Hello command, this is my value!"
}
To make it really simple, the ``name`` field is only to be used for how you want the choice to be presented
through Discord's UI. It's the "appearance" of how you want your choice shown, not the actual returned value
of it. Hence, this is why ``value`` is the second field passed for that, which can be either in the form of
of it. Hence, this is why ``value`` is the second field passed for that, which can be either in the form of
a string or integer. Below is an implementation of this design in the Python code:

.. code-block:: python
from discord_slash.utils.manage_commands import create_option, create_choice
@slash.slash(name="test",
description="This is just a test command, nothing more.",
options=[
Expand All @@ -236,9 +236,9 @@ a string or integer. Below is an implementation of this design in the Python cod
Want to restrict access? Setup permissions!
-------------------------------------------

Slash commands also support the ability to set permissions to allow only certain roles and/or users
to run a slash command. Permissions can be applied to both global and guild based commands. They
are defined per guild, per top-level command (the base command for subcommands), and each guild can have multiple permissions. Here is the table that shows the JSON
Slash commands also support the ability to set permissions to allow only certain roles and/or users
to run a slash command. Permissions can be applied to both global and guild based commands. They
are defined per guild, per top-level command (the base command for subcommands), and each guild can have multiple permissions. Here is the table that shows the JSON
structure of how permissions are represented:

+-------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+
Expand All @@ -251,7 +251,7 @@ structure of how permissions are represented:
| permission | boolean | ``True`` to allow, ``False`` to disallow. |
+-------------+--------------------------------------------+-----------------------------------------------------------------------------------------------------+

How the type parameter works is very simple. Discord has many ids to represent different things. As you can
How the type parameter works is very simple. Discord has many ids to represent different things. As you can
set permissions to apply for User or Role, `ApplicationCommandPermissionType`_ is used. It's a number and
following table shows the supported id types for permissions:

Expand All @@ -270,12 +270,12 @@ This is an example of how a single permission will look when represented as a js
{
"id": 12345678,
"type": 1,
"permission": True
"permission": True
}
Now, let take a look at an example. The slash command decorator has a permissions parameter where
it takes in a dictionary. The key being the guild id to apply permissions on, and value being the list
of permissions to apply. For each permission, we can use the handy ``create_permission`` method to
of permissions to apply. For each permission, we can use the handy ``create_permission`` method to
build the permission json explained above.

In this case, we are setting 2 permissions for a guild with an id of ``12345678``. Firstly, we are allowing
Expand All @@ -297,7 +297,7 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running
async def test(ctx):
await ctx.send(content="Hello World!")
Alternatively, you can use the ``@slash.permission`` decorator to define your guild permissions for the
Alternatively, you can use the ``@slash.permission`` decorator to define your guild permissions for the
command as show in the following example:

.. code-block:: python
Expand All @@ -307,9 +307,9 @@ command as show in the following example:
@slash.slash(name="test",
description="This is just a test command, nothing more.")
@slash.permission(guild_id=12345678,
@slash.permission(guild_id=12345678,
permissions=[
create_permission(99999999, SlashCommandPermissionType.ROLE, True),
create_permission(99999999, SlashCommandPermissionType.ROLE, True),
create_permission(88888888, SlashCommandPermissionType.USER, False)
])
async def test(ctx):
Expand Down Expand Up @@ -426,15 +426,15 @@ Subcommands are way to "nest" your slash commands under one (or more) given name
This table is importantly distinguishing the **library's** naming conventions and not the way that th eDiscord API handles it. The API does subcommand grouping and bases through the options of a slash command, so we decided to create a decorator instead to make this easy for bot developers alike to use. We will not be giving a JSON example of this because of this reason.

.. code-block :: python
# This will appear as "/bot latency" as latency is not an option,
# but apart of the command name itself.
@slash.subcommand(base="bot",
name="latency",
description="Returns the bot's latency.")
async def bot_latency(ctx):
await ctx.send(f"Hello! {round(bot.latency * 1000)} ms.")
If you would like to add a group instead, you may simply base the ``subcommand_group``` kwarg into the decorator. Please note that the slash command limit is 25 commands per subcommand group per subcommand base. (Laymen's term for 25 subcommands in a group, and 25 groups in a base. This is not a global exception and may also apply as a limitation for guild commands.)

Handling my errors.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ line-length = 100

[tool.isort]
profile = "black"
line_length = 100
line_length = 100
2 changes: 1 addition & 1 deletion readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ python:
- method: pip
extra_requirements:
- readthedocs
path: .
path: .

0 comments on commit 50066fc

Please sign in to comment.