获取最后发送的附件 discord.py

huangapple go评论102阅读模式
英文:

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链接。

  1. messages = await channel.history(limit=10).flatten()
  2. for msg in messages:
  3. try:
  4. if msg.attachments:
  5. print((msg.attachments))
  6. except:
  7. 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.

  1. messages = await channel.history(limit=10).flatten()
  2. for msg in messages:
  3. try:
  4. if msg.attachments:
  5. print((msg.attachments))
  6. except: print('no image')

huangapple
  • 本文由 发表于 2023年1月9日 03:21:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定