예제 #1
0
 def format(self, record: logging.LogRecord) -> str:
     frame = inspect.currentframe()
     user = channel = command = messageid = msg = None
     while frame.f_back is not None:
         for key, value in frame.f_locals.items():
             if isinstance(value, discord.ext.commands.Context):
                 user = value.author
                 channel = value.channel
                 command = value.command
                 messageid = value.message.id
                 break
             elif isinstance(value, discord.Message):
                 msg = value
         frame = frame.f_back
     if msg and not command:
         user = msg.author
         channel = msg.channel
         messageid = msg.id
     record.user = user
     record.channel = channel
     record.command = command
     record.messageid = messageid
     return super().format(record)