用户执行命令后,如何删除discord.py中的消息?
我试图编写一个函数,用用户发送的命令删除消息 例如:用户执行命令后,如何删除discord.py中的消息?,discord,discord.py,Discord,Discord.py,我试图编写一个函数,用用户发送的命令删除消息 例如: 用户发送命令/数据包 Bot向命令发送响应 Bot删除用户发送的消息 到目前为止,我所能找到的(对我有帮助的)都是这个堆栈溢出线程: 但是当我使用解决方案中描述的代码时,我只收到了AttributeError:“Bot”对象没有属性“delete\u message” discord.py API引用(/)只显示一些代码在较新版本中发生了更改。 可以说,client.delete_message将更改为message.delete(),如
- 用户发送命令/数据包
- Bot向命令发送响应
- Bot删除用户发送的消息
我不能很好地理解您的问题,但据我所知,当命令执行时,然后在bot发送消息后,您希望删除命令消息,在这种情况下,它是
/delmes
。您可以使用等待ctx.message.delete()
@client.command(pass\u context=True)
异步def delcommes(ctx):
等待ctx.send(“这是对用户命令的响应!”)
等待ctx.message.delete()
好的,谢谢!我现在明白我的问题了!我曾经尝试过ctx.message.delete(),但括号中仍然有ctx.message,就像旧版本discord.py中指出的那样,我在上面链接了一个问题!
import discord
from discord.ext import commands
import random
import json
client = commands.Bot(command_prefix = '/', case_insensitive=True)
@client.command(pass_context=True)
async def delcommes(ctx):
await ctx.send("This is the response to the users command!")
await Message.delete(ctx.message, delay=3)