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

Discord selfbot仅回复自身消息不响应其他用户,如何修改使其支持回复所有用户和机器人?

问题原因与修改方案

核心问题

你的代码目前仅响应自身发送的消息是两个原因导致的:

  • 没有显式配置Discord Intents,默认权限下无法读取其他用户、机器人发送的消息内容
  • Bot实例未显式开启self_bot配置,同时存在冗余的Client实例声明

修改后的代码

import discord
from discord.ext.commands import Bot
import asyncio

# 配置Intents,开启消息读取权限
intents = discord.Intents.default()
intents.message_content = True
intents.guild_messages = True
intents.dm_messages = True

TOKEN = "u token"

# 实例化Bot时显式传入self_bot和intents参数
b = Bot(command_prefix = "x", self_bot=True, intents=intents)

@b.event
async def on_ready():
    print("I ready")

@b.event
async def on_message(message):
    # 若不需要响应自己发送的消息,可以新增判断 if message.author != b.user
    if message.content == "xd":
        await message.channel.send("lmao")

b.run(TOKEN, bot = False)

修改说明

  • 新增Intents配置:必须开启message_content权限才能读取非自身发送的消息内容,额外开启服务器消息、私信消息权限保证所有场景都能触发
  • 实例化Bot时新增self_bot=True参数,明确告知框架这是selfbot实例,需要处理所有可见消息而非仅自身消息
  • 移除了冗余的client = discord.Client()声明,避免和Bot实例冲突

内容的提问来源于stack exchange,提问作者Andres Avendaño Aguilar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 17:18:03