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

Discord删除消息复读机器人无法获取非@提及的删除消息内容问题求助

Discord删除消息复读机器人无法获取非@提及的删除消息内容问题求助

我写了一个Discord机器人,原本功能是复读用户删除的消息。目前机器人响应ping完全正常,也能检测到消息被删除并生成提示,但它没法获取到没有@提及它的删除消息内容——只有当被删消息里@了机器人的时候,它才能正常读取内容,比如消息是@bot, this is a deleted message被删时,机器人能正确获取内容;但如果是this is a deleted message这种没@它的消息被删,机器人就会输出“No text content”的提示。

我是Python新手,非常希望能得到各位的指点,下面是我的代码(带注释),谢谢大家!

import discord
import os
from flask.app import cli
from keep_alive import keep_alive
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
client = discord.Client(intents=discord.Intents.default())
token = os.getenv('token.env')

# Event to detect and log deleted messages
@client.event
async def on_message_delete(message):
     
     # Response message
    response = (
        f" **Deleted Message Alert** \n"
        f"User: {message.author}\n"
        f"{message.content or 'No text content'}"
        )

    # Ignore messages sent by bots
    if message.author.bot:
        return

    # Send the response to the same channel
    await message.channel.send(response)
    
# Event to detect when the bot is pinged
@client.event
async def on_message(message):
    # Check if the bot is mentioned
    if client.user in message.mentions:
        await message.channel.send("Hello!")

    # Ensure other commands and events still work
    await client.process_commands(message)

# Log when the bot is ready
@client.event
async def on_ready():
    print(f"Logged in as {client.user.name} - {client.user.id}")

#server activation
keep_alive()

# Runs the bot
client.run(os.getenv("TOKEN"))

我已经尝试过的方法:

  • 重新编写、格式化代码,但没有任何效果
  • 移除了“检测被ping”的代码段测试,结果除了机器人不再响应ping外,问题依旧存在
  • 删掉了代码里的“No text content” fallback部分,结果机器人只会发送空白的提示消息

备注:内容来源于stack exchange,提问作者techbeezin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 14:40:31