How can i clear messages via slash command in Pycord?

34 Views Asked by At

Since Pycord is kind of a Discord.py fork, i thought i could just use ctx.purge(limit=X), but it does'nt work. Can anyone help me?

This is my code:

@bot.command()

async def purge(ctx, amount: int):

    await ctx.purge(limit=amount)

    await ctx.respond(f"Purged {amount} messages.")
1

There are 1 best solutions below

0
Jerry Zheng On

It is a fork of discord.py so it will carry over a lot of its attributes and methods. discord.Interaction has an attribute for the message and using the message attribute we can retrieve the channel:

https://docs.pycord.dev/en/stable/api/models.html#discord.Interaction.message

message = interaction.message
channel = message.channel

# To purge:
channel.purge(amt)

Purge is an function of discord.TextChannel read more here

If this doesn't work you can print message variable and see the attributes it has.