[Python] Receiving error when attempting to send a file from a deleted message using a...

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I'm attempting to make a discord bot resend the contents of a message, including files, when a message is deleted.

    @bot.event
    async def on_message_delete(message):
    await message.channel.send("I expected that. "+message.author.name+" said \""+message.content+"\"")
    for glorp in message.attachments:
    plorp = glorp.to_file()
    await message.channel.send(file=plorp)


    Currently, the bot successfully sends the message that includes the content of the deleted message, but it does not send any of the attachments.

    In the log, I got this traceback:

    Traceback (most recent call last):
    File "C:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\client.py", line 504, in _run_event
    await coro(*args, **kwargs)
    File "c:\Users\User\OneDrive\Documents\Jarvis\main.py", line 54, in on_message_delete
    await message.channel.send(file=plorp)
    File "C:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\abc.py", line 1686, in send
    with handle_message_parameters(
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
    content=content,
    ^^^^^^^^^^^^^^^^
    ...<13 lines>...
    poll=poll,
    ^^^^^^^^^^
    ) as params:
    ^
    File "C:\Users\User\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\http.py", line 257, in handle_message_parameters
    attachments_payload.append(attachment.to_dict())
    ^^^^^^^^^^^^^^^^^^
    AttributeError: 'coroutine' object has no attribute 'to_dict'


    How can I fix this?

    Continue reading...

Compartilhe esta Página