Skip to content

Commit

Permalink
chore: update wording as requested
Browse files Browse the repository at this point in the history
  • Loading branch information
vcokltfre committed Apr 15, 2021
1 parent fddfc76 commit 15aa872
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bot/resources/tags/customchecks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**Custom Command Checks in discord.py**

You may find yourself in need of a check decorator to do something that doesn't exist in discord.py by default, but fear not, you can make your own! Using discord.py you can use `discord.ext.commands.check` to create you own checks like this:
Often you may find the need to use checks that don't exist by default in discord.py. Fortunately, discord.py provides `discord.ext.commands.check` which allows you to create you own checks like this:
```py
from discord.ext.commands import check, Context

Expand All @@ -9,9 +9,9 @@ def in_any_channel(*channels):
return ctx.channel.id in channels
return check(predicate)
```
There's a fair bit to break down here, so let's start with what we're trying to achieve with this check. As you can probably guess from the name it's locking a command to a **list of channels**. The inner function named `predicate` is used to perform the actual check on the command context. Here you can do anything that requires a `Context` object. This inner function should return `True` if the check is **successful** or `False` if the check **fails**.
This check is to check whether the invoked command is in a given set of channels. The inner function, named `predicate` here, is used to perform the actual check on the command, and check logic should go in this function. It must be an async function, and always provides a single `commands.Context` argument which you can use to create check logic. This check function should return a boolean value indicating whether the check passed (return `True`) or failed (return `False`).

Here's how we might use our new check:
The check can now be used like any other commands check as a decorator of a command, such as this:
```py
@bot.command(name="ping")
@in_any_channel(728343273562701984)
Expand Down

0 comments on commit 15aa872

Please sign in to comment.