Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用签入不一致重写cog_Python_Python 3.x_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 使用签入不一致重写cog

Python 使用签入不一致重写cog,python,python-3.x,discord.py,discord.py-rewrite,Python,Python 3.x,Discord.py,Discord.py Rewrite,这是我的代码,在我的discord rewrite cog中,我从中读取了cog\u检查的代码,但我似乎不知道如何使用它 @commands.command() async def mee(msg): await msg.send("ME") 举一个函数用法的例子或解释就好了。 提前谢谢 它是根据名称定义的。您需要提供一个cog\u检查corroutine来覆盖从cog from discord.ext.commands import Cog, command class MyCog

这是我的代码,在我的discord rewrite cog中,我从中读取了
cog\u检查的代码,但我似乎不知道如何使用它

@commands.command()
async def mee(msg):
    await msg.send("ME")
举一个函数用法的例子或解释就好了。
提前谢谢

它是根据名称定义的。您需要提供一个
cog\u检查
corroutine来覆盖从
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")

它是根据名称定义的。您需要提供一个
cog\u检查
corroutine来覆盖从
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找到答案

def is_me():
定义谓词(ctx):
返回ctx.message.author.id==8530953344815104
返回命令。检查(谓词)
@bot.command()
@是我吗
仅异步定义(ctx):
等待ctx.send('只有你!')

在discord.py找到了答案

def is_me():
定义谓词(ctx):
返回ctx.message.author.id==8530953344815104
返回命令。检查(谓词)
@bot.command()
@是我吗
仅异步定义(ctx):
等待ctx.send('只有你!')

有没有办法只对cog内的单个命令进行检查,或者只有办法对cog内的所有命令进行检查?您可以使用decorator语法,正常地对单个命令进行检查。我还是有点迷茫,请您通过编辑您的答案给我举个例子好吗?这会有很大帮助的。!有没有办法只对cog内的单个命令使用检查,或者只有办法应用于cog内的所有命令?您可以使用decorator语法,正常地对单个命令应用检查。我仍然有点迷茫,请您通过编辑您的答案向我展示一个示例?这会有很大帮助的。!