如果未通过命令传递参数,则向聊天室发送消息

时间:2019-06-30 00:40:31

标签: python-3.x discord.py

有人可以在这个问题上给我一些帮助吗?如果有人尝试使用命令而不给出参数,我会抛出一条消息。

    @feathelp.error
    async def name_feathelp(self, ctx, error):
        if isinstance(error, commands.MissingRequiredArguement):
            await ctx.send("I need the name of the feat you want help on. I can't read minds.")

如果我执行!feathelp而不给我的漫游器加任何参数,它将给我:

discord.ext.commands.errors.MissingRequiredArgument: answer is a required argument that is missing.

使用上述方法,我得到:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord.ext.commands' has no attribute 'MissingRequiredArguement'

在没有上述代码的情况下引发异常时,不理解为什么它不是商品。

    @commands.command()
    @commands.dm_only()
    async def feathelp(self, ctx, *, answer):


        featDictionary = featDict()[0]
        featList = featDict()[1]
        private = ctx.author.send
        answer = str(answer.lower())
        reqStat = featDictionary[0][answer]['stat']
        featStatus = featDictionary[0][answer]['status']
        level = featDictionary[0][answer]['requirements'][0]
        reqStr = featDictionary[0][answer]['requirements'][1]
        reqDex = featDictionary[0][answer]['requirements'][2]
        reqCon = featDictionary[0][answer]['requirements'][3]
        reqFeats = featDictionary[0][answer]['requirements'][4]
        await private(" ''' " + answer.capitalize() + " (" + reqStat + ") (" + featStatus + "):\n" +
                    featDictionary[0][answer]['desc'] +
                    "\nPrerequisites: " + "\nLevel: " + str(level) +
                    "\nStrength: " + str(reqStr) +
                    "\nDexterity: " + str(reqDex) +
                    "\nConstitution: " + str(reqCon) +
                    "\nRequired Feats: " + reqFeats +" ''' ")

1 个答案:

答案 0 :(得分:0)

如果您希望参数为可选,则应将功能更改为:

async def feathelp(self, ctx, *, argument = None):

这将argument更改为可选

对于错误处理程序MissingRequiredArgument不仅在commands.error.MissingRequiredArgument中,而且在commands中。

希望有帮助!