Reputation: 11
I need to attach the chat.log file to the message, but an exception appears
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "c:\Users\vlad0\Desktop\bot\bot.py", line 660, in on_message
await channel.send('***Log for ticket #{id}***'.format(id = text),file = f )
File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\abc.py", line 752, in send
raise InvalidArgument('file parameter must be File')
discord.errors.InvalidArgument: file parameter must be File
My code:
with open(file[0]+'/chat.log','r', encoding='UTF-8') as f:
await channel.send('***Log for ticket #{id}***'.format(id = text),file = f.read() )
The same thing happens when I read using "rb", and the same thing if you just specify the path to the file How do I attach a file to a message?
Upvotes: 1
Views: 4607
Reputation: 60944
The argument to file
must be a discord.File
object:
from discord import File
await channel.send('***Log for ticket #{id}***'.format(id = text), file=File(file[0]+'/chat.log'))
Upvotes: 3