【问题标题】:Discord Bot Needing to Read Webhook Instead of User MessageDiscord Bot 需要读取 Webhook 而不是用户消息
【发布时间】:2021-07-19 14:55:34
【问题描述】:

所以我的不和谐机器人设置为在消息中查找特定关键字,然后在我的服务器中 ping 一个角色。示例:

关键字 = “披萨”

用户留言 --> 我最喜欢的食物是披萨和寿司

机器人消息 --> @Role

但是问题是我需要机器人在 webhook 中找到特定的关键字,我想知道我将如何去做。我已经尝试过通过不同的方式来阅读嵌入,并且似乎没有任何运气,所以我想我会直接寻求帮助。我已经发布了我在这个部分中使用的当前代码。任何帮助将不胜感激。

@client.event
async def on_message(message):
  if (message.channel.id == channel_id):
    for i in range(len(keywords)):
      if keywords[i] in message.content:
          await message.channel.send("<@&role_id>")

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    如果消息是通过 webhook 发送的,webhook_id 属性将不会是 None

    @client.event
    async def on_message(message):
        if message.webhook_id is not None:  # if the message is sent by a webhook
            if (message.channel.id == channel_id):
                for i in range(len(keywords)):
                    if keywords[i] in message.content:
                        await message.channel.send("<@&role_id>")
    

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 2022-11-17
      • 1970-01-01
      • 2020-08-25
      • 2021-07-19
      • 2022-12-09
      • 2022-10-14
      • 2020-07-12
      • 2018-05-30
      相关资源
      最近更新 更多