【问题标题】:How to allow discord bot to respond to webhook. Python. Discord.py如何让不和谐机器人响应 webhook。 Python。不和谐.py
【发布时间】:2021-07-07 04:30:45
【问题描述】:

我在尝试让 webhook 与机器人交互时遇到问题 出于某种原因,机器人不会响应 webhook 发起的命令 有没有办法确保它启动? 否则正常工作

我的命令:

# registering new commands that can be called by the flask webhook
@client.command()
async def new_message_received(ctx, trade_hash: str = ''):
    print(f'New Trade Received! {trade_hash}')
    paxful_cogs = client.get_cog('Paxful_Cogs')
    await paxful_cogs.new_trade_received(trade_hash=trade_hash)
    await ctx.send(f'{trade_hash} executed.')
    print(f'Trade Done Execution! {trade_hash}')

我的 webhook 发送成功,但机器人没有响应。

Bot 响应我,但不响应 webhook。

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    好的,在 python discord 服务器的大力帮助下解决了这个问题。

    @client.event
    async def on_message(message):
        # Manually get the invocation context from the message
        ctx = await client.get_context(message)
    
        # Verify that the context has a command and can be used
        if ctx.valid:
            # Invoke the command using the earlier defined bot/client/command
            await client.invoke(ctx)
    

    https://i.gyazo.com/d23edb65efeeaa834c5de33d70f00484.png

    基本上,我们将覆盖on_message fx,检查消息是否与ctx.valid 匹配我们的前缀/命令结构,然后强制使用client.invoke(ctx) 处理命令,无论它是否来自机器人/ webhook 与否。

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 2022-01-11
      • 2020-10-08
      • 2018-03-20
      • 2020-12-18
      • 2021-10-30
      相关资源
      最近更新 更多