TypeError:“模块”对象不可调用,discord.py

时间:2020-08-24 17:29:33

标签: python python-3.x discord.py

代码:

import discord
from discord.ext.commands import Bot
from discord.ext import commands

client = commands.bot(command_prefix = ".")

@client.event
async def on_ready():
    print("I'm in!")


@client.event
async def on_message(message):
    print(message.content)
    if message.author == client.user:
       return
    
    if message.content.startswith("hello"):
        await message.channel.send('hello!')

@client.event
async def on_member_join(member):
    print("someone's here!")


@client.event
async def on_typing(channel, user, when):
    print("Lol, someone is typing!!1!")

@client.command()
async def answer(ans):
    await ans.send("Here is your answer")

错误:

文件“ /Users/me/documents/bot/bot.py”,第5行,在 客户端= commands.bot(command_prefix =“。”) TypeError:“模块”对象不可调用

我是否还需要安装其他东西作为discord.py?

3 个答案:

答案 0 :(得分:1)

注意小写/大写! commands.bot确实是一个模块https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/bot.py

commands.bot.Bot是可调用对象。由于您已经导入了Bot,只需使用它即可。

client = Bot(command_prefix = ".")

答案 1 :(得分:0)

导入模件时,您可能需要包括模块前缀。

client = discord.commands.bot(command_prefix = ".")

如果这不起作用,我将无能为力。抱歉!

答案 2 :(得分:0)

您有错字,需要使用stdlib.h