Skip to content

Instantly share code, notes, and snippets.

@Painezor
Last active April 20, 2025 16:07
Show Gist options
  • Save Painezor/eb2519022cd2c907b56624105f94b190 to your computer and use it in GitHub Desktop.
Save Painezor/eb2519022cd2c907b56624105f94b190 to your computer and use it in GitHub Desktop.

Revisions

  1. Painezor revised this gist Dec 13, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    @commands.guild_only()
    # Command cannot be used in private messages.

    @commands.dm_only()
    # Command can only be used in private messages.

    @commands.is_owner()
    # Command can only be used by the bot owner.

  2. Painezor revised this gist Apr 17, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -13,13 +13,13 @@
    @commands.bot_has_role(11132312313213)
    # As above, but for the bot itself. (name can be replaced with id)

    @commands.has_any_role(*["role1","foo",11132312313213])
    @commands.has_any_role("role1","foo",11132312313213)
    # Check if user has any of the roles with the names "role1", "foo", or the role with id 11132312313213

    @commands.bot_has_any_role(*roles)
    # As above, but for the bot itself

    @commands.has_permissions(**{ban_members:True, kick_members:True})
    @commands.has_permissions(ban_members=True, kick_members=True)
    # Check if user has all of the passed permissions
    # e.g. this command will require both kick and ban permissions

  3. Painezor revised this gist Mar 12, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -13,13 +13,13 @@
    @commands.bot_has_role(11132312313213)
    # As above, but for the bot itself. (name can be replaced with id)

    @commands.has_any_role("role1","foo",11132312313213)
    @commands.has_any_role(*["role1","foo",11132312313213])
    # Check if user has any of the roles with the names "role1", "foo", or the role with id 11132312313213

    @commands.bot_has_any_role(*roles)
    # As above, but for the bot itself

    @commands.has_permissions(ban_members=True, kick_members=True)
    @commands.has_permissions(**{ban_members:True, kick_members:True})
    # Check if user has all of the passed permissions
    # e.g. this command will require both kick and ban permissions

  4. Painezor revised this gist Mar 12, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -13,13 +13,13 @@
    @commands.bot_has_role(11132312313213)
    # As above, but for the bot itself. (name can be replaced with id)

    @commands.has_any_role(["role1","foo",11132312313213])
    @commands.has_any_role("role1","foo",11132312313213)
    # Check if user has any of the roles with the names "role1", "foo", or the role with id 11132312313213

    @commands.bot_has_any_role(*roles)
    # As above, but for the bot itself

    @commands.has_permissions([ban_members=True, kick_members=True])
    @commands.has_permissions(ban_members=True, kick_members=True)
    # Check if user has all of the passed permissions
    # e.g. this command will require both kick and ban permissions

  5. Painezor revised this gist Jan 25, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Checks.py
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@
    @commands.cooldown(rate,per,BucketType)
    # Limit how often a command can be used, (num per, seconds, BucketType)

    @commands.max_concurrency(number, per=<BucketType.default: 0>, *, wait=False)
    @commands.max_concurrency(number, per=BucketType.default, *, wait=False)
    # Limit how many instances of the command can be running at the same time.
    # Setting wait=True will queue up additional commands. False will raise MaxConcurrencyReached

  6. Painezor revised this gist Jan 25, 2020. 1 changed file with 13 additions and 11 deletions.
    24 changes: 13 additions & 11 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -10,24 +10,24 @@
    @commands.has_role("name")
    # Check if member has a role with the name "name"

    @commands.bot_has_role("name")
    # As above, but for the bot itself.
    @commands.bot_has_role(11132312313213)
    # As above, but for the bot itself. (name can be replaced with id)

    @commands.has_any_role("role1","foo","bar")
    # Check if user has any of the roles with the names "role1", "foo", or "bar"
    @commands.has_any_role(["role1","foo",11132312313213])
    # Check if user has any of the roles with the names "role1", "foo", or the role with id 11132312313213

    @commands.bot_has_any_role("role1","foo","bar")
    @commands.bot_has_any_role(*roles)
    # As above, but for the bot itself

    @commands.has_permissions(**perms)
    # Check if user has any of a list of passed permissions
    # e.g. ban_members=True
    @commands.has_permissions([ban_members=True, kick_members=True])
    # Check if user has all of the passed permissions
    # e.g. this command will require both kick and ban permissions

    @commands.bot_has_permissions(**perms)
    # As above, but for the bot itself.

    @commands.has_guild_permissions()
    @commands.bot_has_guild_permissions()
    @commands.has_guild_permissions(**perms)
    @commands.bot_has_guild_permissions(**perms)
    # As for the two above, but for guild permissions rather than channel permissions.

    @commands.check(myfunction)
    @@ -43,4 +43,6 @@

    @commands.max_concurrency(number, per=<BucketType.default: 0>, *, wait=False)
    # Limit how many instances of the command can be running at the same time.
    # Setting wait=True will queue up additional commands. False will raise MaxConcurrencyReached
    # Setting wait=True will queue up additional commands. False will raise MaxConcurrencyReached

    # Checks can be stacked, and will Raise a CheckFailure if any check fails.
  7. Painezor revised this gist Jan 25, 2020. 1 changed file with 22 additions and 11 deletions.
    33 changes: 22 additions & 11 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    @commands.check(myfunction)
    # Check against your own function that returns those able to use your command
    @commands.guild_only()
    # Command cannot be used in private messages.

    @commands.is_owner()
    # Command can only be used by the bot owner.

    @commands.is_nsfw()
    # Command can only be used in NSFW channels

    @commands.has_role("name")
    # Check if member has a role with the name "name"
    @@ -20,16 +26,21 @@
    @commands.bot_has_permissions(**perms)
    # As above, but for the bot itself.

    @commands.has_guild_permissions()
    @commands.bot_has_guild_permissions()
    # As for the two above, but for guild permissions rather than channel permissions.

    @commands.check(myfunction)
    # Check against your own function that returns those able to use your command

    @commands.check_any(*myfunctions)
    # Command will be ran if the conditions of any of your own check functions are met

    from discord.ext.commands.cooldowns import BucketType
    # BucketType can be BucketType.default, member, user, guild, role, or channel
    @commands.cooldown(rate,per,BucketType)
    # Limit how often a command can be used, (num per, seconds, BucketType)
    # BucketType can be BucketType.default, user, server, or channel

    @commands.guild_only()
    # Rewrite Only: Command cannot be used in private messages. (Replaces no_pm=True)

    @commands.is_owner()
    # Rewrite Only: Command can only be used by the bot owner.

    @commands.is_nsfw()
    # Rewrite Only: Command can only be used in NSFW channels
    @commands.max_concurrency(number, per=<BucketType.default: 0>, *, wait=False)
    # Limit how many instances of the command can be running at the same time.
    # Setting wait=True will queue up additional commands. False will raise MaxConcurrencyReached
  8. Painezor created this gist Sep 13, 2017.
    35 changes: 35 additions & 0 deletions Checks.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    @commands.check(myfunction)
    # Check against your own function that returns those able to use your command

    @commands.has_role("name")
    # Check if member has a role with the name "name"

    @commands.bot_has_role("name")
    # As above, but for the bot itself.

    @commands.has_any_role("role1","foo","bar")
    # Check if user has any of the roles with the names "role1", "foo", or "bar"

    @commands.bot_has_any_role("role1","foo","bar")
    # As above, but for the bot itself

    @commands.has_permissions(**perms)
    # Check if user has any of a list of passed permissions
    # e.g. ban_members=True

    @commands.bot_has_permissions(**perms)
    # As above, but for the bot itself.

    from discord.ext.commands.cooldowns import BucketType
    @commands.cooldown(rate,per,BucketType)
    # Limit how often a command can be used, (num per, seconds, BucketType)
    # BucketType can be BucketType.default, user, server, or channel

    @commands.guild_only()
    # Rewrite Only: Command cannot be used in private messages. (Replaces no_pm=True)

    @commands.is_owner()
    # Rewrite Only: Command can only be used by the bot owner.

    @commands.is_nsfw()
    # Rewrite Only: Command can only be used in NSFW channels