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
>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)