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

discord.py代码运行报错TypeError: 'module'不可调用,求修复方法

解决discord.py中TypeError: 'module' object is not callable的问题

你遇到的错误是因为**discord.bot是一个模块而非可调用的类**,不能直接用它创建Bot实例。

修正方法:

你已经从discord.ext导入了commands,应该用commands.Bot来初始化Bot对象,替换掉原来的discord.bot调用:

import discord
from discord.ext import commands


# 用commands.Bot替代discord.bot
bot = commands.Bot(command_prefix="!", help_command=None)

@bot.event
async def on_ready():
    print(f"Bot logged in as {bot.user}")
    
bot.run("TOKEN")

补充说明:

如果你的discord.py版本是v2.x及以上,也可以使用discord.Bot(注意大写B),但这个类主要适配Slash命令机器人;如果你需要前缀命令(比如!开头的指令),commands.Bot更贴合你的需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 09:30:57