【发布时间】:2020-07-12 18:54:26
【问题描述】:
我对@987654321@ 有疑问(我直接跳过它),并且我知道设置arg: int 会给我带来问题。
你知道解决办法吗?我尝试了很多方法,但我不能
代码:
@client.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def clear(ctx, arg: int):
if not arg:
embed = discord.Embed(
color=discord.Colour.red()
)
embed.set_author(
name="Specifica quante messaggi vuoi cancellare!",
icon_url="https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png"
)
await ctx.send(embed=embed, delete_after=10.0)
return
embed = discord.Embed(
color=discord.Colour.green()
)
embed.set_author(
name=f'Ho cancellato ufficialmente {arg} messaggi!',
icon_url=f'{ctx.author.avatar_url}'
)
await ctx.channel.purge(limit=arg+1)
await ctx.send(embed=embed, delete_after=10.0)
embed = discord.Embed(
color=discord.Colour.dark_gold()
)
embed.set_author(
name=f'{ctx.author._user} ha cancellato {arg}',
icon_url=f'{ctx.author.avatar_url}'
)
embed.add_field(
name='Messaggi cancellati da:',
value=f'{ctx.author._user}',
inline=True
)
embed.add_field(
name='Quantità:',
value=f'{arg}',
inline=True
)
channel = client.get_channel(729553772547932190)
await channel.send(embed=embed)
@clear.error
async def clear_error(ctx, error):
if isinstance(error, commands.CheckFailure):
embed = discord.Embed(
color=discord.Colour.red()
)
embed.set_author(
name="Non ti è permesso cancellare i messaggi!",
icon_url='https://cdn.discordapp.com/attachments/640563710104043530/730639329453670420/DuscePeppe_FRIULI.png'
)
await ctx.send(embed=embed, delete_after=10.0)
【问题讨论】:
-
你需要指定一个默认参数来检查它是否存在
arg: int=-1然后if arg != -1:
标签: python python-asyncio discord.py