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

Python开发Discord Bot遇TypeError:'module'对象不可调用,如何解决?

解决Discord机器人TypeError: 'module' object is not callable错误

问题代码

from discord.ext import commands
import discord

BOT_TOKEN = 'REDACTED'
CHANNEL_ID = 1234
# Not actual CHANNEL_ID int due to privacy

bot = commands.bot(command_prefix = '!', intents = discord.Intents.all())

@bot.event
async def on_ready():
    print('Bot is ready')
    channel = bot.get_channel(CHANNEL_ID)
    await channel.send('Bot is ready')

bot.run(BOT_TOKEN)

报错信息

Traceback (most recent call last):
  File "/Users/[REDACTED INFO]/[REDACTED INFO]/bot.py", line 7, in <module>
    bot = commands.bot(command_prefix = '!', intents = discord.Intents.all())

          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**TypeError: 'module' object is not callable**

解决方案

错误根源是你用了commands.bot,这里的bot是commands模块下的子模块,不是可实例化的类。正确的类名是首字母大写的Bot,修改这一行代码即可:

bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())

修改后重新运行代码,该TypeError即可修复。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 11:23:35