在 discord-rewrite cog 中使用检查

Using check in discord-rewrite cog

所以这是我在 discord-rewrite cog 中的代码,我从 Github 中读取了 cog_check 的代码,但我似乎无法弄清楚如何使用它。

@commands.command()
async def mee(msg):
    await msg.send("ME")

函数用法的例子或对其的解释会很好。 提前致谢!

它是根据名称定义的。您需要提供一个 cog_check 协程来覆盖从 Cog

继承的协程
from discord.ext.commands import Cog, command

class MyCog(Cog):
    def __init__(self, bot):
        self.bot = bot
    async def cog_check(self, ctx):
        return True  # Whatever check you want to do
    @command()
    async def mee(self, ctx):
        await ctx.send("ME")

在 discord.py documentation

处找到了答案
def is_me():
    def predicate(ctx):
        return ctx.message.author.id == 85309593344815104
    return commands.check(predicate)

@bot.command()
@is_me()
async def only_me(ctx):
    await ctx.send('Only you!')