我有一个模块,其中包含以下代码
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,这已经让我感到困扰了一个多月了所以任何帮助都会很棒,谢谢!