공부/discord.py
002. discord.py 개인(자신)에게 개인(DM) 문자 보내기
유찬수
2022. 5. 31. 11:46
※주의※ 봇이 있는 서버에 참여해 있어야만 한다.
일단 개인 id를 가져와 보자.
1. 디스코드 실행
2. 자기가 들어가 있는 서버 선택 후 서버 자기 프로필에 마운스 오른쪽 클릭 id복사하기를 클릭하여 id를 가져온다.
이제 코딩해보자
from discord.ext import commands
import discord
from discord.utils import get
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
user = await bot.fetch_user(user_id='자기 id(''없이)')#보낼 사람을 특정한다.
message = "%s가 시작됐습니다." %(bot.user.name)#메세지 생성
await user.send(message)#그 사람에게 메세지를 보낸다.
await bot.change_presence(status=discord.Status.online, activity=None)#봇의 상태를 online으로 바꾼다.
@bot.command(name = "안녕") #안녕을 받는다
async def hi(ctx):
await ctx.channel.send("Hello")#안녕을 받은 체널에 Hello를 보낸다.
bot.run('자기 토큰(''붙이세요.)')
시작하면 자신에게 dm을 보내는 코딩 이다.
응용하면 그 서버에 있는 다른 사람에게 dm을 보낼 수 있다.