chatGPT와 Discord Bot 만들기 1


아주 간단한 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 처음 만드시는 분들께 참고가 되면 좋겠습니다.

2

👉 이 게시글도 읽어보세요