我收到 'str' 对象没有属性 'callables'

I receive 'str' object has no attribute 'callables'

正在尝试浏览列表并显示在 cmds

中分配的可调用项

这是在__init__.py:

class Cmd(object):
    def __init__(self, callables, func, cooldown=0):
        self.func = func
        self.cooldown = cooldown
        self.next_use = time()
        self.callables = callables

cmds = [
    Cmd(["hello", "hi", "hey"], misc.hello, cooldown=30),
    Cmd(["roll"], misc.roll, cooldown=15),
    Cmd(["potato", "potatoes", "p"], economy.potato, cooldown=15),
    Cmd(["heist"], bet.start_heist, cooldown=15),
    Cmd(["about", "credits"], misc.about, cooldown=15),
    Cmd(["uptime"], misc.uptime, cooldown=15),
    """Cmd(["loyalty"], misc.loyalty, cooldown=15),"""
]

这是在misc.py

def help(bot, prefix, cmds):
    bot.send_message(f"Registered commands (incl. aliases): "
                     + ", ".join([f"{prefix}{'/'.join(cmd.callables[0])}" for cmd in cmds]))

问题在线

bot.send_message(f"Registered commands (incl. aliases): "
                     + ", ".join([f"{prefix}{'/'.join(cmd.callables[0])}"

如评论中所述,您似乎试图通过将 cmds 中的一个条目放在字符串中来注释掉它。由于此字符串没有 callables 属性,因此当 cmds 可能由您的 help 函数处理时会引发 AttributeError

删除或注释掉(使用 # 符号)cmds 的最后一个条目应该可以解决您的问题。例如,

cmds = [
    Cmd(["hello", "hi", "hey"], misc.hello, cooldown=30),
    ...
    Cmd(["uptime"], misc.uptime, cooldown=15),
    # """Cmd(["loyalty"], misc.loyalty, cooldown=15),"""
]