mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-05 17:02:32 -05:00
Use the commands module instead of checks for permission decorators (#5463)
Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
@@ -98,13 +98,13 @@ in various ways:
|
||||
.. code-block:: python
|
||||
|
||||
@commands.command()
|
||||
@checks.admin_or_permissions(manage_guild=True)
|
||||
@commands.admin_or_permissions(manage_guild=True)
|
||||
async def setbaz(self, ctx, new_value):
|
||||
await self.config.guild(ctx.guild).baz.set(new_value)
|
||||
await ctx.send("Value of baz has been changed!")
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
@commands.is_owner()
|
||||
async def setfoobar(self, ctx, new_value):
|
||||
await self.config.foobar.set(new_value)
|
||||
|
||||
@@ -259,7 +259,7 @@ Now let's see an example that uses multiple identifiers:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from redbot.core import Config, commands, checks
|
||||
from redbot.core import Config, commands
|
||||
|
||||
|
||||
class ChannelAccess(commands.Cog):
|
||||
@@ -273,7 +273,7 @@ Now let's see an example that uses multiple identifiers:
|
||||
self.config.register_custom("ChannelAccess", **default_access)
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
@commands.is_owner()
|
||||
async def grantaccess(self, ctx, channel: discord.TextChannel, member: discord.Member):
|
||||
await self.config.custom("ChannelAccess", channel.id, member.id).allowed.set(True)
|
||||
await ctx.send("Member has been granted access to that channel")
|
||||
|
||||
@@ -21,7 +21,7 @@ Basic Usage
|
||||
|
||||
class MyCog(commands.Cog):
|
||||
@commands.command()
|
||||
@checks.admin_or_permissions(ban_members=True)
|
||||
@commands.admin_or_permissions(ban_members=True)
|
||||
async def ban(self, ctx, user: discord.Member, reason: str = None):
|
||||
await ctx.guild.ban(user)
|
||||
case = await modlog.create_case(
|
||||
|
||||
@@ -73,7 +73,7 @@ Any Cog Creator that does not follow these requirements will have their repo rem
|
||||
|
||||
- Cogs that are more than what is able to be run in a simple eval.
|
||||
- Cogs that are more than just a simple API access request.
|
||||
- Cogs that properly use Red utilities, including Config, checks, and any other utility functions.
|
||||
- Cogs that properly use Red utilities, for example Config, or any other utility functions.
|
||||
- Cogs that use event listeners (bot.wait_for or cog-wide listeners) or custom tasks that are efficient and handle exceptions appropriately.
|
||||
- Cogs that handle errors properly.
|
||||
- Cogs that handle permissions properly.
|
||||
@@ -84,7 +84,7 @@ Any Cog Creator that does not follow these requirements will have their repo rem
|
||||
- The default locale must be English.
|
||||
- The main cog class and every command must have a doc-string.
|
||||
- No cog allows for escalation of permissions. (e.g., sending a mass ping through the bot without having permission to do so)
|
||||
- Respect the role hierarchy. Don’t let a lower role have a way to grant a higher role.
|
||||
- Respect the role hierarchy. Don't let a lower role have a way to grant a higher role.
|
||||
- If your cog install comes with any pre-packaged data, use `bundled_data_path()` to access it.
|
||||
- If your cog install creates any non-config data, use `cog_data_path()` to store it.
|
||||
- Unless the cog is intentionally designed to listen to certain input from bots, cogs should ignore input from bots.
|
||||
@@ -138,7 +138,8 @@ While not required for approved Cog Creators, they are still recommended in orde
|
||||
- ``ctx.embed_color``
|
||||
- ``bot.is_automod_immune``
|
||||
|
||||
- Use checks to limit command use when the bot needs special permissions.
|
||||
- Use decorators to limit command use, restrict usage, or define whether the bot needs special permissions.
|
||||
You can find all of the permission and cooldown related decorators under the ``redbot.core.commands`` namespace.
|
||||
- Check against user input before doing things. Common things to check:
|
||||
|
||||
- Resulting output is safe.
|
||||
|
||||
Reference in New Issue
Block a user