Discord.py Clean 命令删除引脚

Discord.py Clean command deletes pins

我正在尝试让这个命令停止删除固定的消息。我在这里看到了一些与此相关的主题,但其中 none 的编码似乎非常适合我的机器人。这是我现在拥有的代码:


@commands.command(aliases=["c", "C", "Clean"])
    @commands.has_permissions(manage_messages=True)
    async def clean(self, ctx, amount: int):
        await ctx.message.delete()
            amount = amount
            await ctx.channel.purge(limit=amount)
            embed = discord.Embed(color=0x4a3d9a, timestamp=ctx.message.created_at)
            embed.set_author(name="Clear", icon_url=ctx.author.avatar_url)
            embed.add_field(name="Success", value=f"Successfully cleaned {amount} messages.")
            embed.set_thumbnail(url=self.client.user.avatar_url)
            embed.set_footer(text="NewHorizon Development | https://NewHorizon-Development.netlify.app", icon_url=self.client.user.avatar_url)
            await ctx.send(embed=embed, delete_after=3)


    @clean.error
    async def clean_error(self, ctx, error):
        await ctx.message.delete()
        if isinstance(error, commands.MissingRequiredArgument):
            embed = discord.Embed(color=0x4a3d9a, timestamp=ctx.message.created_at)
            embed.set_author(name="Whoopsie", icon_url=self.client.user.avatar_url)
            embed.add_field(name="Command Error", value="I'm sorry. but it seems I do not know how many messages you want me to clean.\n\nPlease try again and specify the amount of messages for me to clean")
            embed.set_thumbnail(url=self.client.user.avatar_url)
            embed.set_footer(text="NewHorizon Development | https://NewHorizon-Development.netlify.app", icon_url=self.client.user.avatar_url)
            await ctx.send(embed=embed, delete_after=3)
        else:
            if isinstance(error, commands.MissingPermissions):
                embed = discord.Embed(color=0x4a3d9a, timestamp=ctx.message.created_at)
                embed.set_author(name="Whoopsie", icon_url=ctx.author.avatar_url)
                embed.add_field(name="Command Error", value="I'm sorry, but it seems you do not have the permissions to use this command.")
                embed.set_thumbnail(url=self.client.user.avatar_url)
                embed.set_footer(text="NewHorizon Development | https://NewHorizon-Development.netlify.app", icon_url=self.client.user.avatar_url)
                await ctx.send(embed=embed, delete_after=3)

如有任何帮助,我们将不胜感激。

根据第一条评论的建议,我尝试使用:

@commands.command(aliases=["c", "C", "Clean"])
    @commands.has_permissions(manage_messages=True)
    async def clean(self, ctx, amount: int):
        await ctx.message.delete()
        amount = amount
        await ctx.channel.purge(limit=amount, check=lambda msg: not msg.pinned)
        embed = discord.Embed(color=0x4a3d9a, timestamp=ctx.message.created_at)
        embed.set_author(name="Clear", icon_url=self.client.user.avatar_url)
        embed.add_field(name="Success", value=f"Successfully cleaned {amount} messages.")
        embed.set_thumbnail(url=self.client.user.avatar_url)
        embed.set_footer(text="NewHorizon Development | https://NewHorizon-Development.netlify.app", icon_url=self.client.user.avatar_url)
        await ctx.send(embed=embed, delete_after=3)

然而,这仍然会删除用户图钉。

如果有帮助,我正在使用重写分支。

如果你使用重写: await ctx.channelpurge(limit=amount, check=lambda msg: not msg.pinned)

如果没有,你可以使用purge_fromawait self.bot.purge_from(ctx.channel, limit=amount, check=lambda msg: not msg.pinned)