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
: Python에서 모듈을 깔아주는 pip를 최신 버전으로 올려줍니다. | |
python -m pip install --upgrade pip | |
: Discord.py 모듈을 깔아줍니다. | |
python -m pip install discord | |
: Windows를 사용 중 이면, 좀 더 짧은 명령어가 사용 가능합니다. | |
pip install discord |
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
: cmd(명령 프롬포트)에서 진행 해 주세요. 관리자 권한이 필요하지 않습니다. | |
: Python 명령어를 사용 할 수 있게 Python을 실행시킵니다 | |
python | |
: discord 모듈을 불러옵니다 | |
import discord | |
: discord 모듈 버전을 출력합니다 | |
discord.__version__ |
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
# -*- coding:utf-8 -*- | |
# 위에 구문은 # 빼버리시면 문제 생깁니다. | |
# 가끔가다 애가 인코딩을 잘못 읽어서 오류를 냅니다. 그것을 대비하기 위해 'utf-8'으로 읽으라고 선언합니다. | |
import discord, asyncio # 디스코드 모듈과, 보조 모듈인 asyncio를 불러옵니다. | |
token = "my_token" # 아까 메모해 둔 토큰을 입력합니다 | |
client = discord.Client() # discord.Client() 같은 긴 단어 대신 client를 사용하겠다는 선언입니다. | |
@client.event |
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
if message.content.startswith("!도움말"): # 만약, 채팅이 "!도움말"로 >>시작<< 한다면, | |
await message.channel.send("답변") # "답변"이라는 채팅을 메시지가 보내진 채널에 전송합니다. |
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
# 이번 강좌를 위해서 추가적인 모듈은 불러 올 필요가 없습니다. 단순히 메시지 전송 구문을 아래과 같이 바꾸면 됩니다. | |
embed = discord.Embed(title="메인 제목", description="설명", color=0x62c1cc) # Embed의 기본 틀(색상, 메인 제목, 설명)을 잡아줍니다 | |
embed.set_footer(text="하단 설명") # 하단에 들어가는 조그마한 설명을 잡아줍니다 | |
await message.channel.send(embed=embed) # embed를 포함 한 채로 메시지를 전송합니다. | |
await message.channel.send("할 말", embed=embed) # embed와 메시지를 함께 보내고 싶으시면 이렇게 사용하시면 됩니다. |
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
# 우리가 메인제목과 설명을 작성했던 코드 아래에 써줍시다. | |
# 메시지 전송 전에만 써주면 됩니다. | |
# add_field는 여러 개 추가할 수 있으며, 추가한 순서대로 출력됩니다. | |
embed.add_field(name="소제목", value="설명", inline=True) |
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
# 이것도 메시지 전송 전에만 써주시면 됩니다. | |
# url= 뒤에는 아까 복사한 링크를 써주시면 됩니다. | |
# "나는 메시지를 보낸 유저의 프로필 사진을 가져오고 싶다!" 하시는 분은 url= 뒤에 따옴표 지우시고 message.author.avatar_url 넣으시면 됩니다. | |
# 썸네일 구역에 이미지 넣기 | |
embed.set_thumbnail(url="링크") | |
# 메시지 구역에 이미지 넣기 | |
embed.set_image(url="링크") |
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] |
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
# 메시지 내용에서 "!명령어"를 "가나다라"로 바꾼 다음, 바꾼 내용을 message_replaced 변수에 담습니다. | |
# "가나다라"를 ""로 두시면 메시지 내용에서 "!명령어"를 지워버리는 구문이 됩니다. | |
message_replaced = message.content.replace("!명령어", "가나다라") |
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
# await 메시지변수.add_reaction("Emoji") 로 반응을 추가합니다. | |
# 유저가 입력한 명령어에 반응을 달고 싶으시면 '메시지변수'를 message로, | |
# 전송하신 메시지에 담고 싶으시면 message.channel.send() 구문 앞에 sent = 라고 쓰시고, | |
# '메시지변수'를 sent로 적으시면 됩니다. | |
# 모든 메시지에 대한 반응 추가를 감지하지는 못하고, 특정한 메시지에 대한 반응만 감지 할 수 있습니다. | |
# 그 전에, 아래와 같은 구문을 사용하여 어떤 반응을 추가 할 때만 반응할지 정의합니다. | |
def question_check(reaction, user): # question_check 라는 이름은 마음대로 바꾸셔도 됩니다. | |
# 누구든지 :one:라는 이모지나 :two:라는 이모지를 눌렀을 때 반응하게 됩니다. |
OlderNewer