Search code examples
pythondiscorddiscord.py

How to get a Image in client.wait_for function in discord.py


Im trying to make a avatar changer in discord.py and i need to download the image to set it as the avatar, But i dont know how to get the image in client.wait_for.

I havent really tried alot except

def check(m):
    return m.author.id == ctx.author.id
  message_1 = await client.wait_for("message", check=check)
  message = message_1.content

So please help!


Solution

  • You could check if the message_1 contains any attachments, and if so, if the content_type of the first attachment is an image, like so:

    def check(m):
        return m.author.id == ctx.author.id
    
    message_1 = await client.wait_for("message", check=check)
    
    if message_1.attachments:
        if m.attachments[0].content_type.startswith("image"):
            print("yes")
            # do whatever here
    

    Or what you could also do is add these if statements to your check directly:

    def check(m):
        return (
            m.author.id == ctx.author.id
            and m.attachments
            and m.attachments[0].content_type.startswith("image")
        )
    
    message_1 = await client.wait_for("message", check=check)
    
    print("yes")
    # do whatever here