yusin_YT 1e0511f92377434a9f27b5724c29fbe3
아... 분명 이전에 강의영상이 있었다구요?? 아이구참~~~
제가 다시 쭉 둘러 보니까 제가 설명하는 것 보다! 다른 분들이 올려놓은 것들이 더 이해가 잘 갈거 같아서 제 글을 내렸습니다!!
저는 그냥... 바로 코드하는걸로 들어갈께요...흑
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로 시작할 때만
아래에 코드를 실행하는거에요!!
다음에는! 랜덤뽑기를 만들어볼께요!
질문은 언제나 환영이에요!
댓글이 없습니다.
새로운 댓글을 등록해 주세요!