discord.py中的错误处理程序出错,即使给出了所有必需的参数,也给出了太多的位置参数

时间:2019-04-15 08:59:23

标签: python python-3.x discord.py discord.py-rewrite

我最近一直在编程一个discord bot,并且我一直在尝试学习如何使用齿轮,在我的moderation.py齿轮中,每个命令都有错误处理程序,但是它们都说位置过多即使所有参数都是必需的,也会给出args ...

import random
import discord
from discord.ext import commands
from discord.utils import get

class ModerationCog(commands.Cog):
    def __init__(self, client):
        self.client = client


    @commands.command(aliases=['clear','Purge','Clear'])
    @commands.guild_only()
    @commands.has_permissions(manage_messages=True)
    @commands.bot_has_permissions(manage_messages=True)
    async def purge(self, ctx, amount: int=10):
        deleted = await ctx.channel.purge(limit=amount)
        await ctx.send("Deleted " + str(amount) + " message on behalf of "+ctx.author.mention.format(ctx.author), delete_after=3)

    @purge.error
    async def purge_handler(self, ctx, error):
        if isinstance(error, commands.errors.MissingPermissions):
            await ctx.send("You are missing permissions for that -_-".format(ctx.author))
        elif isinstance(error, commands.errors.BotMissingPermissions):
            await ctx.send("I am missing permissions for that -_-")

代码只是说给purge_handler提供了太多的位置参数。错误:

  

discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:purge_handler()接受2个位置参数,但给出了3个位置

0 个答案:

没有答案