You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在guilded.py中获取用户对机器人消息的回复?

获取Discord机器人消息的用户回复方案

你可以使用Discord.py的wait_for方法监听用户对机器人消息的回复,以下是修改后的完整代码示例:

async def create_channel(message):
    # 发送机器人消息并保存这条消息对象
    bot_reply = await message.reply("Reply to this with the channel name that you want to create")
    
    # 定义检查条件:确保是原用户回复,且回复的是机器人的这条消息
    def check(msg):
        return msg.author == message.author and msg.reference and msg.reference.message_id == bot_reply.id
    
    # 等待用户回复,超时时间可自行调整(这里设为60秒)
    try:
        user_reply = await message.client.wait_for('message', check=check, timeout=60)
        # 获取用户回复的内容
        channel_name = user_reply.content
        # 这里可以添加创建频道的逻辑,比如:
        # await message.guild.create_text_channel(channel_name)
        await user_reply.reply(f"频道 {channel_name} 已创建!")
    except TimeoutError:
        await bot_reply.reply("超时未收到回复,操作已取消。")

关键说明:

  • bot_reply = await message.reply(...):保存机器人发送的消息对象,用于后续验证用户是否针对这条消息回复
  • check函数:过滤无关消息,只接收原命令发起者的回复,且必须是针对机器人这条消息的回复
  • wait_for('message', ...):监听消息事件,直到符合条件的消息出现或超时

内容的提问来源于stack exchange,提问作者LG Блоха

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 15:25:14