简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM