개인 자료란 (JE)

  서버 커뮤니티

Profile yusin12 일반인

yusin_YT 1e0511f92377434a9f27b5724c29fbe3

Profile

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

[1강] 디스코드.py 명령어 만들어 보자.

17 일 전 조회 수 41 추천 수 0

아... 분명 이전에 강의영상이 있었다구요?? 아이구참~~~


제가 다시 쭉 둘러 보니까 제가 설명하는 것 보다! 다른 분들이 올려놓은 것들이 더 이해가 잘 갈거 같아서 제 글을 내렸습니다!!

저는 그냥... 바로 코드하는걸로 들어갈께요...흑


Ctrl + `을 누르면 터미널이 켜져요!

이 터미널에

pip install discord

를 쳐주세요

그 다음에

import discord
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
    print(client.user.id)
    print("준비!")
    game = discord.Game("상태메시지")
    await client.change_presence(status=discord.Status.online, activity=game)
@client.event
async def on_message(message):
    if message.content.startswith('할말'):
        await message.channel.send('할말')
    return




client.run("봇의 토큰")

이렇게 적어주세요!

그리구 실행을 하시기 전에!


https://discord.com/developers/applications


디스코드 만들었던 사이트에서 

이걸 전부 다 체크하시고 실행하면 되요! 이렇게 준비!가 뜨면 디스코드가 보시면 봇이 켜져 있을거에요!!


이제 이 친구에게 할말 을 쓰면 봇이 할말 이라고 답해줄거에요!! (아직 할말이라고 하지 마세요!!)


맞아요!

if message.content.startswith('명령어'):
    await message.channel.send('답장')

if  = 만약

message.content.startswith('명령어') = 채팅방에 '명령어'라는 메시지로 시작하면

:  = 아래에 코드를 실행한다.

await = 답장

message.channel.send = 그 '명령어'를 실행한 채팅방에 '답장'이라는 답장을 한다.

라는 뜻이에요!

그래서 아무튼 할말이라고 했더니...헉!! 계속 나와요!!

이유는 간단해요! 디스코드 봇은 봇이 할말이라고 쳐도 명령어를 실행해줘요!

따라서!

if message.content.startswith('할 말'):
    await message.channel.send('할말')

if message.content.startswith('할말'):
    await message.channel.send('할 말')

로 봐꿔야 해요!


그런데 가끔 구글링이나 유튜브에 쳐보면...

if message.content = 'test':
    await message.channe.send('tester')

라고 되어있는 곳도 있을꺼에요!! 이 둘에 차이는!!

메시지에 test라는 문자가 있다면 아래에 코드를 실행한다! 라는 뜻이에요!!

반면에 message.content.startswith('test')는 test로 시작할 때만

아래에 코드를 실행하는거에요!!


다음에는! 랜덤뽑기를 만들어볼께요!

질문은 언제나 환영이에요!

Warning
댓글이 없습니다.

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

뉴스 및 창작물
/files/thumbnails/893/458/003/262x150.crop.jpg?20230326143407

업데이트

마인크래프트 베타 및 프리퓨 1.19.80.22 업데이트

Dalsu

2023-03-26

0

/files/thumbnails/707/458/003/262x150.crop.jpg?20230326093903

모드

Create 0.51 관련 소식

BMlight

2023-03-26

0

/files/thumbnails/046/458/003/262x150.crop.jpg?20230325122447

소식

마인크래프트 1.19.3, 19.4 옵티파인 정식 출시 2

Dalsu

2023-03-25

0

/files/thumbnails/694/457/003/262x150.crop.jpg?20230324221008

업데이트

마인크래프트 베드락 에디션 1.19.72 업데이트

Dalsu

2023-03-24

0

/files/thumbnails/659/457/003/262x150.crop.jpg?20230324200901

업데이트

마인크래프트 베드락 에디션 1.19.71 업데이트

Dalsu

2023-03-24

0