如何在 Pycord 中通过斜杠命令清除消息?

问题描述 投票:0回答:1

由于 Pycord 是一种 Discord.py 分支,我以为我可以只使用

ctx.purge(limit=X)
,但它不起作用。有人可以帮助我吗?

这是我的代码:

@bot.command()

async def purge(ctx, amount: int):

    await ctx.purge(limit=amount)

    await ctx.respond(f"Purged {amount} messages.")
attributeerror pycord purge
1个回答
0
投票

它是discord.py的一个分支,因此它将继承它的许多属性和方法。

discord.Interaction
有一个消息属性,使用消息属性我们可以检索通道:

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

message = interaction.message
channel = message.channel

# To purge:
channel.purge(amt)

Purge 是不和谐的功能。TextChannel 了解更多这里

如果这不起作用,您可以打印

message
变量并查看它具有的属性。

© www.soinside.com 2019 - 2024. All rights reserved.