Start Py-Cord

imnyang·2022년 7월 29일
0

https://blog.naver.com/imnotnyang/222834061471

일단 discord.py가 다시 재개발이 진행중이지만 언제 나올지 모르는 상황이기 때문에 일단 py-cord로 진행을 하게 되었습니다.

- 일단 설치부터

python3 -m pip install py-cord
설치가 완료되었다면 일단 main.py부터 시작해봅시다.

- main.py : # discord.py와 매우 비슷한

discord.py 1.7.3 code

import discord
from discord.ext import commands

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

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
    user = await bot.fetch_user("My ID")
    await user.send("✅ㅣ봇이 준비되었습니다!")
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="..도움말"))

@bot.command()
async def 안녕(ctx):
    await ctx.send(f"Hello! World! `Pong! {round(round(bot.latency, 4)*1000)}ms`")

bot.run(str(os.getenv('TOKEN')))

py-cord 2.0.0 code

import discord

bot = discord.Bot()

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
    user = await bot.fetch_user("My ID")
    await user.send("✅ㅣ봇이 준비되었습니다!")
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="슬커로 알아보세요!"))

# @bot.command()도 작동합니다.
'''
@bot.command()
async def 안녕(ctx):
    await ctx.respond(f"Hello! World! `Pong! {round(round(bot.latency, 4)*1000)}ms`")
'''

@bot.slash_command()
async def 안녕(ctx):
    await ctx.respond(f"Hello! World! `Pong! {round(round(bot.latency, 4)*1000)}ms`")

bot.run(str(os.getenv('TOKEN')))

별로 바뀌는건 없습니다.
@bot.slash_command() -> @bot.command(),
send(reply) -> respond

이런식으로 바뀝니다.

간단하게 이전이 가능합니다.

1부는 이렇게 끝내겠습니다.

imnyang#5100

profile
아임냥이다

0개의 댓글