AverageLua
AverageLua

Reputation: 13

Uploading a txt with discord.py on_message()

I'm trying to send a text file with discord.py through an on_message() event. So far the most I've done is this:

with open('file.txt', 'rb') as fp:
  await message.channel.send(file=discord.file(fp, 'TestFile'))

(I obviously started the bot and the on_message event works).

Whenever this runs though it gives an error saying "TypeError: 'module' object is not callable". The "module" in this situation is import discord. I've been stuck on this issue for 2 days now and I would appreciate any help.

Upvotes: 0

Views: 774

Answers (1)

Jacob Lee
Jacob Lee

Reputation: 4700

You might be looking for discord.File, not discord.file.

with open('file.txt', 'rb') as fp:
  await message.channel.send(file=discord.File(fp, 'TestFile'))

If you were to do a bit of experimentation...

>>> import discord
>>> type(discord.file)
<class 'module`>
>>> type(discord.File)
<class 'type'>
>>>

... you would see that, yes, discord.file is a module, while you are looking for discord.File, the type.

Upvotes: 0

Related Questions