003. discord.py 역할 mention하기

2022. 5. 31. 11:58공부/discord.py

일단 역할 아이디를 가져와 보자.

서버 위 프로필에 간다.그리고 화 살표 클릭

그러면 이렇게 뜬다.

그리고 서버설정 클릭

위 그림 중 역할 클릭

이렇게 뜬다 그중 원하는 역할 옆에 •••클릭하여 아이디 복사

 

코딩

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('자기 토큰(''붙이세요.)')

성공