Discord python,如何获取所有上传到频道的文件和图片?

Discord python, how to get all files and images uploaded to a channel?

如何下载频道中发布的所有文件和图片? 感谢您的任何回复。


for channel in ctx.guild.text_channels:
    async for message in channel.history(limit=100):
        for attachment in message.attachments:
            attachment.save()

我正在使用的代码给我带来了麻烦。

基本上,使用async for ... in channel.history() (documentation) to iterate over the messages, then use message.attachments (documentation) to get the attachment objects. If you then want to save the attachments to your machine, use attachment.save() (documentation)