【问题标题】:Get the height of an attached image in discord.py在 discord.py 中获取附加图像的高度
【发布时间】:2020-10-12 15:37:30
【问题描述】:

我想在 discord.py 中获取附加到消息的图像的高度。这是我的代码:

if message.content(discord.Attachment.height > 0):
  await message.channel.send('Your media file is restricted!')

运行时出现以下错误:

error: TypeError: '>' not supported between instances of 'member_descriptor' and 'int'

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    discord.Attachment.height 是对象discord.Attachmentheight 成员的描述符。这不引用任何特定对象,因此您需要获取特定消息上特定附件的height 属性。

    获取邮件附件的高度:

    1. 使用message.attachments 获取邮件的附件列表。这将是discord.Attachment 类型的对象列表。请注意,如果没有附件,此列表将为空。

    2. 获取特定附件的高度。例如,如果邮件有一个附件,您将使用:

    message.attachments[0].height
    

    请注意,高度属性仅适用于图像和视频。您可能需要使用discord.Attachmentfilename 成员检查文件类型是否正确

    【讨论】:

      猜你喜欢
      • 2012-03-27
      • 2010-09-11
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2013-09-01
      相关资源
      最近更新 更多