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

Discord自机器人开发报错:Intents对象无self_messages属性

问题解决方法

你的错误是因为discord.Intents里根本没有self_messages这个属性,而且混用了discord和selfcord库的组件导致配置错误。以下是修正后的完整代码和关键修改说明:

修正后的代码

import selfcord
from selfcord.ext import commands

# 使用selfcord专属的Intents配置
intents = selfcord.Intents.default()
# 开启消息内容权限(必须开启才能识别命令前缀)
intents.message_content = True
# 开启消息接收权限
intents.messages = True

# 命令前缀设为$,对应你要的$smile指令
bot = commands.Bot(command_prefix="$", self_bot=True, intents=intents)

@bot.command(name="smile")
async def smile(ctx):
    await ctx.send("😄")

# 仅通过bot.run完成登录,不要重复调用selfcord.login
bot.run("MY TOKEN", bot=False)

关键修改点

  • 删掉了冗余的discord库导入,全程使用selfcord的组件,避免库之间的配置冲突
  • 把discord.Intents替换为selfcord.Intents,自机器人的意图配置必须用selfcord的体系
  • 移除了不存在的intents.self_messages = True,换成自机器人处理命令必需的message_content和messages意图
  • 命令前缀从"."改成"$",命令名从"troll"改成"smile",完美匹配你要的$smile触发指令
  • 去掉了多余的selfcord.login("MY TOKEN"),bot.run已经包含登录逻辑,重复调用会导致异常

内容的提问来源于stack exchange,提问作者Myepcischoolstack

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 09:32:10