def format_objects(*objects, attr=None, dec: str="", sep: str=None):
""" Return a formatted string of objects (User, Member, Channel or Server) using
the given decorator and the given separator.
:param objects: Any object with attributes, preferably User, Member, Channel or Server.
:param attr: The attribute to get from any object. Defaults to object names.
:param dec: String to decorate around each object.
:param sep: Separator between each argument.
:return: str: the formatted objects.
"""
if not objects:
return
first_object = objects[0]
if attr is None:
if isinstance(first_object, discord.User):
attr = "display_name"
elif isinstance(first_object, discord.Channel) or isinstance(first_object, discord.Role):
attr = "mention"
sep = " "
elif isinstance(first_object, discord.Server):
attr = "name"
sep = sep if sep is not None else ", "
return sep.join(dec + getattr(m, attr) + dec for m in objects)
评论列表
文章目录