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

Discord Python报错:bot对象无event属性问题求助

问题排查:AttributeError: module 'discord.client' has no attribute 'event'

错误根源

  • 你错误地将commands.bot(模块)赋值给了client,正确的类是commands.Bot(注意首字母大写)。
  • 未实例化Bot类:commands.Bot是一个类,必须创建实例并传入必要参数(如命令前缀、Intents)才能使用其event装饰器。

修正后的代码

import discord
from discord.ext import commands

# 实例化Bot类,指定命令前缀和默认Intents
client = commands.Bot(command_prefix='!', intents=discord.Intents.default())

@client.event
async def on_ready():
    print("Bot is ready to execute action")

# 替换为你的Bot令牌,从Discord开发者平台获取
client.run('YOUR_BOT_TOKEN')

注意事项

  • Intents是Discord Bot的必填项,discord.Intents.default()提供基础权限,若需要读取消息等更多功能,需在开发者门户开启对应Intents并在代码中声明。
  • 务必保护好你的Bot令牌,不要公开或提交到版本控制系统。

内容的提问来源于stack exchange,提问作者That one noob coder

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 14:21:12