我想知道这段代码有什么问题。应该下载图像,然后将其从目录中删除:
import discord
import re
import os
token = ''
class MyClient(discord.Client):
async def on_ready(self):
print('Name: {0}'.format(self.user.name))
print('ID: {0}'.format(self.user.id))
print('{0} Is Online'.format(self.user))
async def on_message(self, message):
attachmentimg = re.compile(r'(.(jpe?g|JPE?G|png|PNG))')
attachmentgif = re.compile(r'(.(gif|GIF))')
image = re.compile(r'https?:\/\/\S*?\/[^\/.]+\.(jpg|png)')
if len(message.attachments) > 0 and attachmentimg.search(message.attachments[0].url) and message.channel.id == 516468839190626336:
await message.attachments[0].save('C:/xxxx/xxxx/xxxx/xxxx/Images/' + message.attachments[0].filename)
print('Downloaded: {0}'.format(message.attachments[0].filename))
os.remove('C:/xxxx/xxxx/xxxx/xxxx/Images/' + message.attachments[0].filename)
client = MyClient()
client.run(token, bot=False, reconnect=True)
是否在将文件添加到目录之前将其从目录中删除?在控制台上,它显示文件已下载,但是我看不到从文件夹中添加和删除文件的过程。我知道代码可以正常工作,因为当我不使用os.remove时,我可以看到文件出现在文件夹中。