본문으로 건너뛰기

chatGPT와 Discord Bot 만들기 1

이태극

2023.04.15


아주 간단한 Discord Bot을 만들어봤어요.
디스코드 채팅에서 '!ping' 을 입력하면 bot이 'Pong!' 이라고 말하는 기능이에요.

chatGPT가 기초 코드를 잘 알려주지 못하는 것 같아서 공유드립니다.

아래는 chatGPT가 짜준 코드에요.
import discord
from discord.ext import commands
 
intents = discord.Intents.default()
client = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print('Bot is ready.')

@client.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run('your-bot-token-here') # Replace with your bot token

이 코드는 에러가 발생해요.
에러 코드를 입력해도 해결하지 못했어요.

결국 Slackoverflow의 도움을 받았어요.
코드 3번줄과 4번줄을 수정했습니다.

아래는 수정해서 동작하는 코드에요.
import discord
from discord.ext import commands

intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=intents)

@client.event
async def on_ready():
    print('Bot is ready.')


# Enter '!ping' -> 'Pong!'
@client.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run('your-bot-token-here')

이외에는 딱히 문제가 없었어요.
discord bot 처음 만드시는 분들께 참고가 되면 좋겠습니다.

함께 이야기해요 0

로그인하고 댓글을 남겨 주세요

필요한 AI 정보만
메일함에 쏙쏙 넣어드려요.

지금 핫한 AI 소식부터 직접 해 본 사례까지, 월요일마다 무료로 받아보세요

이런 사례도 있어요

사례 전체 보기