python - 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
谁能帮我解决这个错误?
这个错误的原因是什么?谁能准确地向我解释一下?
解决方案
首先,错误消息告诉您您正在调用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'
推荐阅读
- ruby-on-rails - Mailgun 上的“smtp;550 封邮件应该有一个或没有回复标题,而不是 2”
- reactjs - 使用 react-google-recaptcha 和 react-final-form
- javascript - For 循环问题 JavaScript
- javascript - 请求失败,状态码 409:React 前端和 Python Flask 后端
- java - 交换链表节点后递归 toString 函数的堆栈溢出
- javascript - React Hooks 的奇怪的 'id's 和 checkboxes 行为
- python - 为每一行运行一个函数并创建一个新的 Column Pandas Dataframe
- python - 如何去除文件中文本中的\n,然后计算python中超过n个字母的文本单词?
- jira - 是否有 JQL 查询来检查特定人员是否在过去一周更新了 Jira 票证中的任何内容?
- arrays - 数据类型数组