首页 > 解决方案 > Python Discord bot 错误:模块对象不可调用

问题描述

这是什么错误?

import discord
from discord.ext import commands
import asyncio
import aiofiles 
import os
import requests
import json
from keep_alive import keep_alive
bot = commands.bot (command_prefix="!")
Traceback (most recent call last):
  File "file.py", line 9, in <module>
    bot = commands.bot (command_prefix="!")
TypeError: 'module' object is not callable

谁能帮我解决这个错误?

这个错误的原因是什么?谁能准确地向我解释一下?

标签: pythondiscordbots

解决方案


首先,错误消息告诉您您正在调用bot的是模块而不是类或方法,因此您可以尝试执行以下操作,其中包含访问模块内的类:

bot = commands.Bot (command_prefix="!") 
#or if you realize that you forgot a capital 'B' so it's like accessing the module in that way without a capital 'B'

推荐阅读