Discord 설정
마지막 업데이트
이 페이지에서는
core/discord bot 생성, 요청하는 gateway intent, handler가 받는 Input을 설명합니다.생성자
- bot, err := discord.New(token)
New는 token이 비어 있으면 token is required를 반환합니다. Bot <token>으로 인증된 discordgo.Session을 만들고 메시지와 인터랙션 handler를 등록하지만 연결하지는 않습니다. 옵션은 없습니다.Gateway intent
| Intent | 요청하는 이유 |
|---|---|
IntentGuilds | gateway가 GUILD_CREATE를 보내 discordgo의 state 캐시를 채움. 없으면 Input.ChannelName이 항상 "" |
IntentsGuildMessages | 서버 채널의 메시지 |
IntentDirectMessages | bot에게 보낸 다이렉트 메시지 |
IntentMessageContent | 메시지 텍스트와 첨부 파일 |
IntentMessageContent는 권한이 필요한 intent입니다. Discord Developer Portal의 Bot 설정에서 Message Content Intent를 활성화하세요. 그렇지 않으면 대부분의 메시지에서 Input.Text가 비어 있습니다(Discord는 DM과 bot을 멘션한 메시지에만 내용을 보냅니다).Start
Start(ctx)는 먼저 REST User("@me")를 호출해 token을 검증한 다음 Session.Open()으로 WebSocket에 연결합니다. 잘못된 token은 연결을 열기 전 첫 단계에서 실패합니다. bot이 직접 보낸 메시지는 discordgo의 세션 state로 걸러지므로 handler에 도달하지 않습니다.Input
| 필드 | 타입 | 내용 |
|---|---|---|
ChannelID | string | 메시지 또는 프롬프트의 채널 |
ChannelName | string | 추가 요청 없이 state 캐시에서 읽음. DM이거나 캐시에 없으면 "" |
GuildID | string | 서버 ID. DM이면 "" |
MessageID | string | 사용자의 메시지. 모달과 선택 답변에서는 프롬프트 메시지 |
UserID / Username | string | 보낸 사람. 인터랙션에서는 길드 멤버에서, DM에서는 사용자에서 가져옴 |
Text | string | 메시지 내용, 모달 답변, 또는 단일 선택 값 |
Attachments | []*discordgo.MessageAttachment | 업로드된 모든 파일(이미지, 파일, 오디오). ContentType으로 구분 |
CallbackPicks | []string | SendMultiSelect 메뉴에서 고른 값 |
Raw | *discordgo.MessageCreate | 일반 메시지의 SDK 이벤트. 인터랙션 답변에서는 nil |
모든 ID는 Discord snowflake 문자열입니다.