【问题标题】:Discord.py if message is a gifDiscord.py 如果消息是 gif
【发布时间】:2021-08-04 22:38:24
【问题描述】:

我希望在不和谐中发布 gif/图像时运行一个函数

@bot.event()
async def on_message(message):
    if (message.type == discord.MessageType.gif):
        print("Gif")

我明白了

"packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 134, in on_message
    if (message.type == discord.MessageType.gif):
AttributeError: type object 'MessageType' has no attribute 'gif'

【问题讨论】:

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


【解决方案1】:

MessageType 没有这样的属性。您将需要尝试不同的方法。
例如,您可以检查邮件是否有(一个)附件,如果有,检查 .gif 是否是文件结尾。

@bot.event()
async def on_message(message):
    if len(message.attachements) > 0:
        for attachement in message.attachements:
            if ".gif" in attachement.filename.lower():
                print("Gif")

【讨论】:

    【解决方案2】:

    只是添加一个额外的答案,如果您要隔离的是特定的 MEME,则上述解决方案将不起作用,因为它们不是“附件”

    您需要查看 message.content 内部并查找“gif”,类似于上述方法。

    @bot.event()
        async def on_message(message):
            if "gif" in message.content:
                #Do things if gif found, but this will also detecting someone typing gif
            if "http" in message.content:
                #do things but this will also prevent all hyperlinks. 
    

    【讨论】:

      猜你喜欢
      • 2022-06-18
      • 2018-06-29
      • 2021-09-14
      • 2021-05-17
      • 2021-07-08
      • 2017-06-23
      • 2021-03-17
      • 1970-01-01
      • 2019-02-20
      相关资源
      最近更新 更多