Last active
March 18, 2020 12:13
-
-
Save hwahyang1/87681180a76ec76d59758162f50e49f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 우리가 보통 @멘션을 하면 <@유저ID> 의 형태로 입력됩니다. | |
# 우리는 이 점을 이용해서 유저 정보를 담은 변수까지 만들어 보겠습니다. | |
ids = re.findall(r'\d+', message.content) # 메시지에서 숫자만 다 뽑아내서 list로 저장합니다. | |
# 이 아래 구문은 명령어에 숫자가 없다는 가정 하에 작성되었습니다. 명령어에 숫자가 있을 경우, [0]을 다른 숫자로 바꿔주셔야 합니다. | |
# print(ids) 구문으로 모든 list를 보실 수 있습니다. 출력되는 내용을 참고해서 다른 숫자로 바꿔주시면 됩니다. | |
# list는 ['0번', '1번', '2번', ... ] 의 형태로 저장되는데, 첫번째 따옴표에 들어가는 내용이 0번입니다. 1번 아닙니다. | |
target = ids[0] | |
# 이 구문은 우리가 방금 찾아낸 ID를 이용해서 유저 정보를 user_info라는 변수에 담아내는 함수입니다. | |
# get_user 이라는 함수는 문자열이 아닌 정수만을 입력 받기 때문에, int()를 써서 정수로 변환을 시켜줍니다. | |
# user_info 변수는 message.author 변수를 쓰듯이 쓰시면 됩니다. | |
user_info = client.get_user(int(target)) | |
# 공식 문서를 읽으시는 분들을 위해 알려드리자면, user_info는 class discord.user 로 반환됩니다. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment