개인 자료란 (JE)

  서버 커뮤니티

Profile Hunter 대표칭호 없음

jw_h 9832cceeeb1d4415b94988962fe7d340

Profile

커뮤니티 소통 개발하기 디스코드

[ 2강 ] - 상태메세지와 임베드 작성하기

2020.05.15 조회 수 258 추천 수 0

안녕하세요! 디코 대화봇 만들기 두번째입니다!

1강 보러가기 : https://www.koreaminecraft.net/dev_lecture/1694021 


1강을 본 후 그대로 봇을 만드신후 이 강의를 보시는걸 권장합니다!


어쨌든 시작합니다:)

우선 상태메세지 부터 하겠습니다!


messages = ["상태메세지"]
    while True:
        await client.change_presence(status=discord.Status.online, activity=discord.Game(name=messages[0]))
        messages.append(messages.pop(0))


이게 상태메세지 코드입니다.

그러니까 그 코드를 붙이면 이렇게 됩니다.


import discord 
client = discord.Client()
@client.event
async def on_ready():
    print("봇이 실행될때 콘솔창에 뜰 메세지")
    print(client.user.name)  
    print(client.user.id)
    print('_______________________________________________')
    messages = ["상태메세지"]
    while True:
        await client.change_presence(status=discord.Status.online, activity=discord.Game(name=messages[0]))
        messages.append(messages.pop(0))


@client.event
async def on_message(message):
     if message.content == '!안녕':
            await message.channel.send('안녕?')
            
client.run('봇 토큰')

이렇게 생겼습니다.

그럼 이제 상태메세지로  -- 한마포 강의 작성 이 떠야겠죠?

1754a94f6ca609743110e2ab157f9e2c.png

이렇게 뜹니다! 성공 이네요!


이제 임베드 작성을 해보겠습니다!

임베드는 이렇게 생겼습니다

07395f7c09e01d7cacc249e346c81408.png


우선 코드는 이렇습니다


if message.content == '!임베드':

        embed=discord.Embed(color=0x00FF00, title="제목", description="부제목")

        embed.set_footer(text="내용")

        await message.channel.send(embed=embed)


그럼 이걸 이제 추가해보겠습니다. (설명은 밑에 있습니다.)


import discord 


client = discord.Client()


@client.event
async def on_ready():
    print("봇이 실행될때 콘솔창에 뜰 메세지")
    print(client.user.name)  
    print(client.user.id)
    print('_______________________________________________')
    messages = ["상태메세지"]    
        while True:        
        await client.change_presence(status=discord.Status.online, activity=discord.Game(name=messages[0]))   
        messages.append(messages.pop(0))


@client.event
async def on_message(message):
    if message.content == '!안녕':
            await message.channel.send('안녕?')
    
    elif message.content == '!임베드':
            embed=discord.Embed(color=0x00FF00, title="제목", description="부제목")
            embed.set_footer(text="내용")
            await message.channel.send(embed=embed)
            
client.run('봇 토큰')

어쨌든 이렇게 하면 이제 임베드가 작동합니다.

설명 들어갑니다


Q) 21번 줄에 왜 if 가 아니라 elif 가 들어가나요?

A) 그냥 보기 편해서 elif를 썼습니다. if로 쓰셔도 상관 없어요 (elif = else if 의 줄임말)


Q) 22번줄 에 있는 color=0x00ff00 는 무엇인가요? 

A) 임베드 메세지 왼쪽에 있는 선 같은 거 색입니다. 0x00ff00 는 html 컬러 코드 입니다.

    예시) 빨간색은 - 0xff0000  컬러코드를 구한후 앞에 0x 를 붙여야 합니다!


tip: 컬러 코드는 RGB (red, green, blue) 형식 입니다. 그래서 ( 000000 ) <-- 컬러 코드의 원리 

 (맨처음 두글자 -> 빨간색의 정도,  중간에 두글자 -> 초록색의 정도,  끝에 두글자 파란색의 정도)

EX) FFFF00 (빨간색과 초록색) --> 노란색  

이렇게 기본적인 컬러 코드에 원리만 알면 그냥 코드 입력으로 원하는 색을 찾을 수 있습니다.


갑자기 미술 수업이 돼버렸네요 ^^7

어쨌든 


참고로 제목은 title, 부제목은 description,  내용은 footer 입니다.

어쨌든 이렇게 코드를 입력 한후..

0749b348615f25339ad4a9388ad171eb.png


이러면 임베드 작성 성공입니다!  이제 원하는 내용으로 바꾸면 진짜 완벽해 지겠죠?

다음 강의에서는 상태 메세지와 임베드를 좀더 자세히 다뤄보겠습니다.

명령어도 공부해서 올릴 만한게 있으면 올릴게요!








Warning
댓글이 없습니다.

새로운 댓글을 등록해 주세요!

뉴스 및 창작물
/files/thumbnails/520/751/003/262x150.crop.jpg?20240328020349

레드스톤

마인크래프트 노트블록으로 만든 『 Bling‐Bang‐Bang‐Born 』 1

Sonttukk

2024-03-23

1

/files/thumbnails/467/742/003/262x150.crop.jpg?20240311163123

레드스톤

[노트블럭커버] MILGRAM -ミルグラム(밀그램)- / 아마네 「숙청 행진」 제 2심 2

리비온

2024-03-11

0

/files/thumbnails/846/741/003/262x150.crop.jpg?20240310221214

레드스톤

워든 vs 라마 200마리 1

GlassesFilm

2024-03-10

0

/files/thumbnails/542/739/003/262x150.crop.jpg?20240309070457

레드스톤

[고인의 명복을 빕니다][노트블럭]드래곤볼 GT 오프닝 - 점점 마음이 끌려

리비온

2024-03-09

0

/files/thumbnails/326/738/003/262x150.crop.jpg?20240328020414

레드스톤

마인크래프트 노트블록으로 만든 『 Build Our Machine 』

Sonttukk

2024-03-07

0