简体   繁体   中英

Issue with Purge command in Discord.py

Pretty much, for some reason the actual purging works, but it wont send the response embed after its purged. Sometimes it does, sometimes it just spams terminal with errors.

Heres is my code:

@tree.command(name= "purge", description="Purge messages in a channel", guild=discord.Object(id=guildId))
@app_commands.checks.has_permissions(manage_messages=True)
async def purge(interaction, limit: int):
    await interaction.channel.purge(limit=limit)
    embed = discord.Embed(description=f"Purged {limit} message(s)", color=0x3375FF)
    await interaction.response.send_message(embed=embed)

Honestly, im not too sure what is wrong with it. I tried it without an embed and that still didnt work.

https://pastebin.com/uibRCN1F Here is a link to the error I am getting in the termina

It might be that your interaction is timing out. Perhaps try deferring and then using the followup property to send your message later.

@tree.command(name= "purge", description="Purge messages in a channel", guild=discord.Object(id=guildId))
@app_commands.checks.has_permissions(manage_messages=True)
async def purge(interaction, limit: int):
    await interaction.response.defer()
    await interaction.channel.purge(limit=limit)
    embed = discord.Embed(description=f"Purged {limit} message(s)", color=0x3375FF)
    await interaction.channel.send(embed=embed)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM