Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Makeing my first discord bot while learning python…. Bot wont post the picture i want it to

Ok so im still learing and discord is the first API I decided to work with. So far after a few teaks and adjustments ive gotten a good bit to work. Then I thought a welcome message would be great to make. So heres the code and the error:

@client.event
async def on_member_join(members):
    channel = client.get_channel(919804032011341824)
    with open('my_image.png') as f:
        picture = discord.File(f)
    await channel.send('Welcome user! Its not safe to go alone. Here take this!', picture)

Error that shows:

Ignoring exception in on_member_join
Traceback (most recent call last):
  File "E:\Python Projects\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\ccarr\PycharmProjects\pythonProject\Discord Bot\main.py", line 33, in on_member_join
    await channel.send('Welcome user! Its not safe to go alone. Here take this!', picture)
TypeError: send() takes from 1 to 2 positional arguments but 3 were given

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Open the file in binary mode. discord.File takes a binary input.

In order to send files, you need to specify file or files as an argument in the function.

with open("image.png", "rb") as f:
    picture = discord.File(f)

await channel.send("...", file=picture)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading