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

Python Discord机器人报错:'function' object has no attribute 'event' 求助

问题解决:'function' object has no attribute 'event' 错误修复

错误原因

  • 导入了multiprocessing.connection.Client,与discord的Client类重名,@Client.event调用的是multiprocessing的Client类,该类没有event属性,触发报错。
  • 事件函数名不符合Discord.py规范,自定义的FunctionName不会被机器人识别为就绪事件。
  • 打印语句格式存在问题,输出内容会连在一起,可读性差。

修正后的代码

import discord  
import random

client = discord.Client(intents=discord.Intents.default())

@client.event
async def on_ready():
    print(f'Vezi ca sunt on {client.user}')

关键修正点

  • 删除无用的from http import client和from multiprocessing.connection import Client导入,彻底解决命名冲突。
  • 将@Client.event改为@client.event,调用你创建的discord客户端实例的event装饰器。
  • 事件函数名改为on_ready,这是Discord.py约定的客户端就绪时触发的事件名称。
  • 使用f-string简化打印语句,并添加空格优化输出格式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 04:55:19