- 파이썬이라는 언어도 모르고 학교선배를 놀리기위해 시작한 디스코드 봇 제작 회고록
- 현재 가장 애착을 가지고 운영중인 프로젝트
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
client = discord.Client()
token = (inputToken)
@bot.event
async def on_ready():
print("김기담 뚱땡이!")
game = discord.Game("pigman")
await client.change_presence(status=discord.Status.online, activity=game)
@bot.command()
async def 김기담(ctx):
await ctx.send("뚱땡이!")
@bot.command()
async def 이기훈(ctx):
await ctx.send("알고리듬 플레티넘2!")
@bot.command()
async def 김민창(ctx):
await ctx.send("너무잘생겨서 빛이납니다!")
@bot.command()
async def version(ctx):
await ctx.send("ver 1.0")
bot.run(token)
지금 보면 너무나도 단순한 초기 코드다.
단순 응답 핑퐁으로 구성되어 있다.
import discord
from discord.ext import commands
discord 라이브러리 하나가 추가되었다.
cmd
를 열어 python -m pip install discord
를 통해 라이브러리 설치를 한다.
파이썬을 활용하여 봇을 제작하기 위해 제공하는 가장 쉬운 라이브러리이다.
bot = commands.Bot(command_prefix='!')
command_prefix='!'
코드를 통하여 사용자의 요청은 !
로 시작해야 봇에서 읽는다는 의미다.@bot.command()
async def 김기담(ctx):
await ctx.send("뚱땡이!")
@bot.command()
로 함수임을 선언한다.!
다음에 온 사용자의 요청이 def
다음과 같다면 응답을 한다.async
, await
를 통해 비동기 처리를 했다.(순차적으로 진행되어야 하기 때문)놀랍게도 이정도만으로도 신기했었고, 잘놀았었다.
다음은 embed
와 랜덤응답등을 가져오겠습니다.