python www.example.com中的清除斜线命令discord.py

mhd8tkvw  于 2023-03-11  发布在  Python
关注(0)|答案(2)|浏览(167)

在开始我想指出的是,我不使用py-cord模块,只有discord.py。我想创建一个/ clear命令。问题是当应用程序必须返回成功删除用户xyz的n条消息的反馈时。
有一个错误提到
等待交互。响应。发送消息(内容=内容,短暂=真)
是一种未知的相互作用
所有代码斜杠命令:

client = MyClient(intents=intents)
t = app_commands.CommandTree(client)

@t.command(name="clear", description="Clear n messages specific user", guild=discord.Object(id=867851000286806016))
async def self(interaction: discord.Interaction, amount: int, member: discord.Member):
    channel = interaction.channel

    def check_author(m):
        return m.author.id == member.id
    await channel.purge(limit=amount, check=check_author)
    content = f"Successfully deleted {amount} messages from {member.name}"
    await interaction.response.send_message(content=content, ephemeral=True)
client.run(discord_TOKEN)

最后,我想指出的是,bot删除了发送的消息数量,只有bot应用程序的反馈信息丢失了。
我收到消息:应用程序没有响应

gmxoilav

gmxoilav1#

用这个,希望我能帮你.

client = MyClient(intents=intents)
t = app_commands.CommandTree(client)

@t.command(name="clear", description="Clear n messages specific user", guild=discord.Object(id=867851000286806016))
async def self(ctx, interaction: discord.Interaction, amount: int, member: discord.Member):
    channel = interaction.channel

        def check_author(m):
            return m.author.id == member.id
        await ctx.channel.purge(limit=amount, check=check_author)
        await ctx.send(f"Successfully deleted {amount} messages from {member.name}")
ioekq8ef

ioekq8ef2#

我做了这个命令为我的机器人和工作!

@t.command(name="clear",description="Delete Messages automatically from the current channel")
async def cl(bot, number:int, member:discord.Member = None):
  channel = bot.channel
  if number > 50:
    number = 50
  def check_(m):
    return m.author == member
  if not member:
    await channel.purge(limit=number)
  else:
    await channel.purge(limit=number,check=check_)
  await bot.response.send_message(f"Deleted: {number}, from this channel.")

相关问题