英文:
Get last sent attachment discord.py
问题
我需要获取之前在频道中发送的附件,以用作参数。
我使用了await ctx.get_channel(channel).history(limit=10).flatten()[0]
来获取之前发送的消息,只是不知道如何获取消息中最近发送的附件。
英文:
I need to get the previously sent attachment in a channel to use as an argument
I used await ctx.get_channel(channel).history(limit=10).flatten()[0]
to get previously sent messages I just don't know how I would go about getting the most recently sent attachment from the messages
答案1
得分: 0
这是我从我的机器人中获取以前发送的带有附件的代码片段。我认为这可能是你需要的东西。它应该打印出附件的discord bucket链接。
messages = await channel.history(limit=10).flatten()
for msg in messages:
try:
if msg.attachments:
print((msg.attachments))
except:
print('没有图片')
英文:
This is a code snippet I have from my bot that gets previously sent messages with their attachments. I think this is what you might need. It should print a link to the discord bucket with the attachment.
messages = await channel.history(limit=10).flatten()
for msg in messages:
try:
if msg.attachments:
print((msg.attachments))
except: print('no image')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论