[ad_1]
I’m trying to implement a function in my command with discord.py (v2.0) that deletes the bot’s output message when the invoking command has been edited. Here is my implementation:
out_img = await ctx.send(image)
while True:
tasks = [
asyncio.create_task(self.bot.wait_for(
"message_edit",
timeout=react_timeout
), name="msg_edit")
]
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
finished: asyncio.Task = list(done)[0]
for task in pending:
try:
task.cancel()
except asyncio.CancelledError:
pass
action = finished.get_name()
result = finished.result()
if action == "msg_edit":
try:
if out_img is not None:
await out_img.delete()
break
except asyncio.TimeoutError:
break
Suppose that the name of the command is test
and the bot prefix is !
:
User: !test 1
Bot: output 1
User: !test 2
Bot: output 2
When I edit !test 2
, the bot should only delete output 2
, but it instead deletes both output 1
and output 2
.
So I am wondering what check needs to implemented here, so that the bot will only delete output 2
when !test 2
is edited. Thanks.
[ad_2]