강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

lsh030210님의 프로필 이미지
lsh030210

작성한 질문수

디스코드 봇 만드는데 유튜브랑 똑같이하는데 왜 에러일까요

작성

·

115

0

import discord, asyncio

client = discord.Client()

@client.event
async def on_ready(): # 봇이 실행되면 한 번 실행됨
    print("/n이세현따까리")
    await client.change_presence(status=discord.Status.online, activity=discord.Game("이세현따까리"))

@client.event
async def on_message(message):
    if message.content == "테스트": # 메세지 감지
        await message.channel.send ("{} | {}, Hello".format(message.author, message.author.mention))
        await message.author.send ("{} | {}, User, Hello".format(message.author, message.author.mention))


# 봇을 실행시키기 위한 토큰을 작성해주는 곳
client.run('discord token 이건 나중에 입력')

여기에 마지막 디스코드 토큰을 입력하면은


TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents'

이렇게 오류가 뜨는데 뭐가 문제일까요 ㅠㅠ

답변 1

0

안녕하세요, 인프런 AI 인턴입니다.

lsh030210님, 문의하신 디스코드 봇 관련 에러는 디스코드 API의 최신 업데이트와 관련이 있어 보입니다. 최근 디스코드는 봇의 이벤트 처리를 위해 intents를 필수로 지정해야 합니다. intents는 봇이 서버에서 어떤 종류의 이벤트를 수신할 것인지 정의하는 설정입니다.

에러 메시지인 TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents'Client 객체를 초기화할 때 필요한 intents 인자가 없다는 내용입니다. 따라서 Intents를 설정하여 Client 객체를 생성해야 합니다.

디스코드 봇에 필요한 최소한의 코드 변경 예제는 다음과 같습니다:

import discord

intents = discord.Intents.default()  # 기본 인텐트를 사용. 모든 이벤트를 받음
intents.messages = True  # 메시지를 읽기 위해 필요

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print("\n이세현따까리")
    await client.change_presence(status=discord.Status.online, activity=discord.Game("이세현따까리"))

@client.event
async def on_message(message):
    if message.content == "테스트":
        await message.channel.send("{} | {}, Hello".format(message.author, message.author.mention))
        await message.author.send("{} | {}, User, Hello".format(message.author, message.author.mention))

client.run('여기에_디스코드_봇_토큰_입력')

discord.Intents.default()를 통해 기본 인텐트 객체를 생성한 후, 필요한 이벤트에 따라서 해당 인텐트의 속성을 활성화하면 됩니다. 예를 들어, 메시지 읽기를 위해서는 intents.messagesTrue로 설정되어야 합니다.

이렇게 수정하여 진행해보시기 바랍니다. 추가적인 도움이 필요하다면 언제든지 문의해주세요.

lsh030210님의 프로필 이미지
lsh030210

작성한 질문수

질문하기