【问题标题】:Discord.py - bot deletes message after it sendsDiscord.py - 机器人在发送后删除消息
【发布时间】:2021-10-14 00:32:37
【问题描述】:

我最近一直在尝试这样做,以便当有人键入特定命令时,机器人会删除他们的消息。我之前尝试过的一切都不起作用,所以我完全不知道该怎么做。我是 discord.py 的新手,所以我的知识非常有限。

#making sure the command only works in the specific channel
async def is_channel(ctx):
    return ctx.channel.id == 873501773971726346

#the actual code
@client.command(case_sensitive=True)
@commands.check(is_channel)
async def resus(ctx,*, saymsg=None):
    if saymsg==None:
        return await ctx.send("To reserve a username type - !resus (your discord tag) (the username you want) (if you want verification) You can also add some extra information if you would like. Any spam/troll reservations will result in a warning and or mute.")
        


    sayEmbed = discord.Embed(title=f"{ctx.author.name} Said", color = discord.Color.blue(), description=f"{saymsg}")
    sayEmbed.timestamp = ctx.message.created_at
    channelf = client.get_channel(873564203535958047)
    await channelf.send(embed = sayEmbed)

【问题讨论】:

  • 只用await ctx.message.delete()?
  • @Dominik 谢谢,但我是不是把它放在删除用户的消息上?

标签: python python-3.x discord.py


【解决方案1】:

这是我通常做的,但在等待输入时,但你可以在普通消息上使用它

  title = "Something...",
  description = "||This request will timeout in 60s||"
  )
  await ctx.send(embed=embed)
  try:
    amount_of_codes = await client.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=60.0)
  except asyncio.TimeoutError:
    await ctx.channel.send("Request timed out")

【讨论】:

    【解决方案2】:

    就在您要放置的 if 语句的正上方 await ctx.message.delete() 这将删除他们的消息,然后运行您的其余代码。

    【讨论】:

      猜你喜欢
      • 2018-08-16
      • 1970-01-01
      • 2020-11-04
      • 2020-10-10
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 2018-11-25
      • 2019-03-01
      相关资源
      最近更新 更多