AttributeError:模块“DiscordoragiSearch”没有属性“isValidMessage”

2024-03-29 14:07:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个模块,它有以下代码

import DiscordoragiSearch

...

@Discord.client.event
async def on_message(message):
    print('Message recieved')
    #Is the message valid (i.e. it's not made by Discordoragi and I haven't seen it already). If no, try to add it to the "already seen pile" and skip to the next message. If yes, keep going.
    if not (DiscordoragiSearch.isValidMessage(message)):
        try:
            if not (DatabaseHandler.messageExists(message.id)):
                DatabaseHandler.addMessage(message.id, message.author.id, message.server.id, False)
        except Exception:
            traceback.print_exc()
            pass
    else:
        await process_message(message)

这里是来自DiscordoragiSearch.py的相关代码,它与另一个文件位于同一目录中。你知道吗

#Checks if the message is valid (i.e. not already seen, not a post by Roboragi and the parent commenter isn't Roboragi)
def isValidMessage(message):
    try:
        if (DatabaseHandler.messageExists(message.id)):
            return False

        try:
            if (message.author.name == USERNAME):
                DatabaseHandler.addMessage(message.id, message.author.id, message.server.id, False)
                return False
        except:
            pass

        return True

    except:
        traceback.print_exc()
        return False

这个方法是在模块的基础上定义的,但是当我运行代码时,我得到以下错误

File "/home/james/discordoragi/roboragi/AnimeBot.py", line 225, in on_message
if not (DiscordoragiSearch.isValidMessage(message)):
AttributeError: module 'DiscordoragiSearch' has no attribute 'isValidMessage'

两个模块的完整代码都可以找到here如果你想了解更多的信息,我会尽力提供,这已经困扰了我一个多月了,所以任何帮助都会很棒,谢谢!你知道吗


Tags: 模块andthe代码idfalsemessagereturn