【问题标题】:Python Discord bot error: module object is not callablePython Discord bot 错误:模块对象不可调用
【发布时间】:2021-06-12 21:49:13
【问题描述】:

这是什么错误?

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

谁能帮我解决这个错误?

这个错误的原因是什么?谁能给我详细解释一下?

【问题讨论】:

  • 看起来 commands.bot 是一个模块而不是前缀。查看 discord 库的文档并查看正确用法

标签: python discord bots


【解决方案1】:

首先,错误信息告诉你,你正在调用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'

【讨论】:

    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 2013-09-19
    • 2012-06-10
    • 2021-04-22
    • 2020-12-31
    相关资源
    最近更新 更多