mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Docs] Add awaits and missing imports in usage examples (#2860)
Well, the modlog examples had to be changed a lot, because `await` obviously won't work in regular method.
This commit is contained in:
parent
be184b57dd
commit
3e80edcdfd
@ -16,15 +16,16 @@ Basic Usage
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from redbot.core import bank
|
from redbot.core import bank, commands
|
||||||
|
import discord
|
||||||
|
|
||||||
class MyCog:
|
class MyCog(commands.Cog):
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def balance(self, ctx, user: discord.Member = None):
|
async def balance(self, ctx, user: discord.Member = None):
|
||||||
if user is None:
|
if user is None:
|
||||||
user = ctx.author
|
user = ctx.author
|
||||||
bal = bank.get_balance(user)
|
bal = await bank.get_balance(user)
|
||||||
currency = bank.get_currency_name(ctx.guild)
|
currency = await bank.get_currency_name(ctx.guild)
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"{}'s balance is {} {}".format(
|
"{}'s balance is {} {}".format(
|
||||||
user.display_name, bal, currency
|
user.display_name, bal, currency
|
||||||
|
|||||||
@ -16,17 +16,17 @@ Basic Usage
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from redbot.core import modlog
|
from redbot.core import commands, modlog
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
class MyCog:
|
class MyCog(commands.Cog):
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@checks.admin_or_permissions(ban_members=True)
|
@checks.admin_or_permissions(ban_members=True)
|
||||||
async def ban(self, ctx, user: discord.Member, reason: str = None):
|
async def ban(self, ctx, user: discord.Member, reason: str = None):
|
||||||
await ctx.guild.ban(user)
|
await ctx.guild.ban(user)
|
||||||
case = modlog.create_case(
|
case = await modlog.create_case(
|
||||||
ctx.guild, ctx.message.created_at, "ban", user,
|
ctx.bot, ctx.guild, ctx.message.created_at, action="ban",
|
||||||
ctx.author, reason, until=None, channel=None
|
user=user, moderator=ctx.author, reason=reason
|
||||||
)
|
)
|
||||||
await ctx.send("Done. It was about time.")
|
await ctx.send("Done. It was about time.")
|
||||||
|
|
||||||
@ -35,50 +35,65 @@ Basic Usage
|
|||||||
Registering Case types
|
Registering Case types
|
||||||
**********************
|
**********************
|
||||||
|
|
||||||
To register a single case type:
|
To register case types, use an asynchronous ``initialize()`` method and call
|
||||||
|
it from your setup function:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from redbot.core import modlog
|
# mycog/mycog.py
|
||||||
|
from redbot.core import modlog, commands
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
class MyCog:
|
class MyCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
|
||||||
|
async def initialize(self):
|
||||||
|
await self.register_casetypes()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def register_casetypes():
|
||||||
|
# Registering a single casetype
|
||||||
ban_case = {
|
ban_case = {
|
||||||
"name": "ban",
|
"name": "ban",
|
||||||
"default_setting": True,
|
"default_setting": True,
|
||||||
"image": ":hammer:",
|
"image": "\N{HAMMER}",
|
||||||
"case_str": "Ban",
|
"case_str": "Ban",
|
||||||
"audit_type": "ban"
|
# audit_type should be omitted if the action doesn't show
|
||||||
|
# up in the audit log.
|
||||||
|
"audit_type": "ban",
|
||||||
}
|
}
|
||||||
modlog.register_casetype(**ban_case)
|
try:
|
||||||
|
await modlog.register_casetype(**ban_case)
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
To register multiple case types:
|
# Registering multiple casetypes
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from redbot.core import modlog
|
|
||||||
import discord
|
|
||||||
|
|
||||||
class MyCog:
|
|
||||||
def __init__(self, bot):
|
|
||||||
new_types = [
|
new_types = [
|
||||||
{
|
{
|
||||||
"name": "ban",
|
"name": "hackban",
|
||||||
"default_setting": True,
|
"default_setting": True,
|
||||||
"image": ":hammer:",
|
"image": "\N{BUST IN SILHOUETTE}\N{HAMMER}",
|
||||||
"case_str": "Ban",
|
"case_str": "Hackban",
|
||||||
"audit_type": "ban"
|
"audit_type": "ban",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "kick",
|
"name": "kick",
|
||||||
"default_setting": True,
|
"default_setting": True,
|
||||||
"image": ":boot:",
|
"image": "\N{WOMANS BOOTS}",
|
||||||
"case_str": "Kick",
|
"case_str": "Kick",
|
||||||
"audit_type": "kick"
|
"audit_type": "kick"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
modlog.register_casetypes(new_types)
|
await modlog.register_casetypes(new_types)
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# mycog/__init__.py
|
||||||
|
from .mycog import MyCog
|
||||||
|
|
||||||
|
async def setup(bot):
|
||||||
|
cog = MyCog()
|
||||||
|
await cog.initialize()
|
||||||
|
bot.add_cog(cog)
|
||||||
|
|
||||||
.. important::
|
.. important::
|
||||||
Image should be the emoji you want to represent your case type with.
|
Image should be the emoji you want to represent your case type with.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user