从Dropbox使用discord.py上传到Discord

问题描述

我制作了一个DropBox机器人,该机器人可以访问该帐户上的所有文件夹,并将令牌添加到我不和谐的机器人的代码中。启用对files.content.readfiles.Metadata.read的访问。

仅发布URL时,某些文件(例如mp3文件)没有预览,因此我实际上想使用漫游器将文件上传到DropBox文件夹中。

我阅读了DropBox api文档File PropertiesFiles部分,但是找不到如何返回类似文件的对象的方法。现在,我想制作图像和音频文件

我尝试过:

@client.command()
async def test(ctx):
    print("Test was called.")
    
    file_name = "stonks.jpg"
    my_file = dropBox.files('/Reaction Pics/' + file_name)
    await ctx.channel.send(file=my_file)

但是出现以下错误:(我已经检查了我的保管箱API是否可以访问该文件。)

    my_file = dropBox.files('/Reaction Pics/' + file_name)
TypeError: 'module' object is not callable

解决方法

dropbox.files是一个模块,而不是与Dropbox上的文件进行交互的方法。

相反,要从Dropbox获取文件内容(以便可以将其上传到其他位置),应使用the files_download method。有an example of using that here

(或者,您可以使用files_download_to_file首先将其保存到磁盘。Example here。)