mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Create updated leaderboards
This commit is contained in:
parent
829729c8db
commit
06dc3d3fb9
9 changed files with 205 additions and 102 deletions
33
functions/utils.py
Normal file
33
functions/utils.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from typing import Union
|
||||
|
||||
from discord import ApplicationContext
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from data import constants
|
||||
|
||||
|
||||
def get_display_name(ctx: Union[ApplicationContext, Context], user_id: int) -> str:
|
||||
author = ctx.author if isinstance(ctx, Context) else ctx.user
|
||||
|
||||
# Check if this is a DM, or the user is not in the guild
|
||||
if ctx.guild is None or ctx.guild.get_member(user_id) is None:
|
||||
# User is the author, no need to fetch their name
|
||||
if user_id == author.id:
|
||||
return author.display_name
|
||||
|
||||
# Get member instance from CoC
|
||||
COC = ctx.bot.get_guild(int(constants.DeZandbak))
|
||||
member = COC.get_member(user_id)
|
||||
if member is not None:
|
||||
return member.display_name
|
||||
|
||||
# Try to fetch the user
|
||||
user = ctx.bot.get_user(user_id)
|
||||
if user is not None:
|
||||
return user.name
|
||||
|
||||
# User couldn't be found
|
||||
return f"[? | {user_id}]"
|
||||
|
||||
mem = ctx.guild.get_member(user_id)
|
||||
return mem.display_name
|
||||
Loading…
Add table
Add a link
Reference in a new issue