简体   繁体   English

类型错误:“模块”对象不可调用,discord.py

[英]TypeError: 'module' object is not callable, discord.py

code:代码:

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")

error:错误:

File "/Users/me/documents/bot/bot.py", line 5, in client = commands.bot(command_prefix = ".") TypeError: 'module' object is not callable文件 "/Users/me/documents/bot/bot.py", line 5, in client = commands.bot(command_prefix = ".") TypeError: 'module' object is not callable

Do i have to install anything else as discord.py?我是否必须安装其他任何东西作为 discord.py?

Mind lower/upper cases!注意小写/大写! commands.bot is a module indeed https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/bot.py commands.bot确实是一个模块https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/bot.py

commands.bot.Bot is the callable object. commands.bot.Bot是可调用对象。 Since you have imported Bot already, just use that.由于您已经导入了Bot ,只需使用它即可。

client = Bot(command_prefix = ".")

When Importing Moduals, You Might Need To Include The Module Prefix.导入模块时,您可能需要包含模块前缀。

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

If This doesn't work, I can't help.如果这不起作用,我无能为力。 Sorry!对不起!

你有一个错字,你需要使用client = commands.Bot(command_prefix=".")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM