删除机器人等待使用 discord.py 的消息

Remove a message that the bot waited for using discord.py

基本上,我正在尝试制作一个自动角色机器人,它从用户那里获取消息,然后删除该消息并在之后更新角色消息。到目前为止我的代码是:

  @commands.command()
  @commands.has_any_role(786342585479593984, 787715167437324330)
  async def rrtest(self, ctx, *, msg):
    loop = True
    j = "\n"

    messagetext = [msg]
    rolemessage = await ctx.send(f"```{j.join(messagetext)}```")

    message = await ctx.send("Hold on!")
    time.sleep(2)

    while loop:
      await message.edit(content="```Type the role you want to assign \n\nNo need to mention, just type the role name```")
      msg = await self.client.wait_for('message', check=self.check(ctx.author), timeout=30)
      # ^^^ this is the message i want to delete   

我将使用什么代码来删除 msg

使用方法.delete()

await msg.delete()

同时使用 await asyncio.sleep 而不是 time.sleep,这样它就不会阻塞您的整个代码。