초보개발자의 초보블로그
Hello World

Coding/Python

Discord bot with Python #1

Complish_dev 2021. 5. 27. 22:21
반응형
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name) # 토큰으로 로그인 된 bot 객체에서 discord.User 클래스를 가져온 뒤 name 프로퍼티를 출력
    print(bot.user.id) # 위와 같은 클래스에서 id 프로퍼티 출력
    print('------')

@bot.command()
async def ping(ctx):
    await ctx.send(f'pong! {round(round(bot.latency, 4)*1000)}ms') # 봇의 핑을 pong! 이라는 메세지와 함께 전송한다. f-string은 위에 서술되어 있다시피 버전 3.6 이상부터 사용 가능하다.

@bot.command(name="1234")
async def _1234(ctx):
    await ctx.send("5678")

bot.run('token')
728x90
반응형

'Coding > Python' 카테고리의 다른 글

파이썬 리스트 원소 다양한 추가 방법  (0) 2022.03.03
파이썬 정규식 기본(?)  (0) 2021.05.04
파이썬 tkinter 1강  (0) 2021.03.09
loading