尝试在未经禁止权限的情况下禁止用户时发生错误
Error occurs when trying to ban user without ban permission
我得到:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: ban_error() takes 2 positional arguments but 3 were given
每当我尝试使用这个命令时:
(我正在使用齿轮)
@commands.command(name="ban", pass_context=True)
@has_permissions(ban_members=True)
async def _ban(self, ctx, member : discord.Member = None, *, reason:str = None):
if member == None:
await ctx.send("Please mention a user.")
if reason == None:
reason = "N/A"
else:
ban=discord.Embed(title=f"You have been banned from {ctx.guild.name}", color=0x61187c)
ban.add_field(name="Reason:", value=f"{reason}", inline=True)
ban.set_footer(text="( ͡° ͜ʖ ͡°)")
await member.send(embed=ban)
embed=discord.Embed(title=f"Successfully Banned {member}", color=0x61187c)
embed.add_field(name="Reason:", value=f"{reason}", inline=True)
embed.set_footer(text="( ͡° ͜ʖ ͡°)")
await ctx.send(embed=embed)
await member.ban(reason=reason)
@_ban.error
async def ban_error(error, ctx):
if isinstance(error, MissingPermissions):
channel = message.channel
text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
await channel.send(text)
我很确定这是因为我的原因,但我不确定。
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: ban_error() takes 2 positional arguments but 3 were given
错误不言而喻。
您应该尝试为 async def ban_error
实现 3 个参数(您不必全部使用它们,只需确保其中有 3 个,因为库提供了 3 个参数。
我得到:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: ban_error() takes 2 positional arguments but 3 were given
每当我尝试使用这个命令时: (我正在使用齿轮)
@commands.command(name="ban", pass_context=True)
@has_permissions(ban_members=True)
async def _ban(self, ctx, member : discord.Member = None, *, reason:str = None):
if member == None:
await ctx.send("Please mention a user.")
if reason == None:
reason = "N/A"
else:
ban=discord.Embed(title=f"You have been banned from {ctx.guild.name}", color=0x61187c)
ban.add_field(name="Reason:", value=f"{reason}", inline=True)
ban.set_footer(text="( ͡° ͜ʖ ͡°)")
await member.send(embed=ban)
embed=discord.Embed(title=f"Successfully Banned {member}", color=0x61187c)
embed.add_field(name="Reason:", value=f"{reason}", inline=True)
embed.set_footer(text="( ͡° ͜ʖ ͡°)")
await ctx.send(embed=embed)
await member.ban(reason=reason)
@_ban.error
async def ban_error(error, ctx):
if isinstance(error, MissingPermissions):
channel = message.channel
text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
await channel.send(text)
我很确定这是因为我的原因,但我不确定。
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: ban_error() takes 2 positional arguments but 3 were given
错误不言而喻。
您应该尝试为 async def ban_error
实现 3 个参数(您不必全部使用它们,只需确保其中有 3 个,因为库提供了 3 个参数。