Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"fmt"


"github.com/Goscord/goscord"
"github.com/Goscord/goscord/discord"
"github.com/Goscord/goscord/goscord"
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/gateway"
"github.com/Goscord/goscord/goscord/gateway/event"
)
Expand All @@ -53,16 +53,15 @@ func main() {
Intents: gateway.IntentGuildMessages,
})

client.On(event.EventReady, func() {
fmt.Println("Logged in as " + client.Me().Tag())
})

client.On(event.EventMessageCreate, func(msg *discord.Message) {
if msg.Content == "ping" {
client.Channel.SendMessage(msg.ChannelId, "Pong ! 🏓")
}
})
client.On(event.EventReady, func() {
fmt.Println("Logged in as " + client.Me().Tag())
})

client.On(event.EventMessageCreate, func(msg *discord.Message) {
if msg.Content == "ping" {
client.Channel.SendMessage(msg.ChannelId, "Pong ! 🏓")
}
})

client.Login()

Expand Down
11 changes: 10 additions & 1 deletion goscord/discord/channel.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package discord

import (
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/bytedance/sonic"
"time"
)
Expand Down Expand Up @@ -173,6 +172,16 @@ type AllowedMentions struct {
RepliedUsers bool `json:"replied_users"`
}

type MessageReaction struct {
UserId string `json:"user_id"`
ChannelId string `json:"channel_id"`
MessageId string `json:"message_id"`
GuildId string `json:"guild_id"`
Member *GuildMember `json:"member"`
Emoji *Emoji `json:"emoji"`
MessageAuthorId string `json:"message_author_id"`
}

type Message struct {
Id string `json:"id"`
ChannelId string `json:"channel_id"`
Expand Down
1 change: 0 additions & 1 deletion goscord/discord/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package discord

import (
"encoding/json"
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/bytedance/sonic"
)

Expand Down
22 changes: 22 additions & 0 deletions goscord/gateway/event/message_reaction_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package event

import (
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/rest"
"github.com/bytedance/sonic"
)

type MessageReactionAdd struct {
Data *discord.MessageReaction `json:"d"`
}

func NewMessageReactionAdd(rest *rest.Client, data []byte) (*MessageReactionAdd, error) {
pk := new(MessageReactionAdd)

err := sonic.Unmarshal(data, pk)

if err != nil {
return nil, err
}
return pk, nil
}
16 changes: 16 additions & 0 deletions goscord/gateway/reaction_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gateway

import (
"github.com/Goscord/goscord/goscord/gateway/event"
)

type MessageReactionHandler struct{}

func (_ *MessageReactionHandler) Handle(s *Session, data []byte) {
ev, err := event.NewMessageReactionAdd(s.rest, data)

if err != nil {
return
}
s.Publish(event.EventMessageReactionAdd, ev.Data)
}
2 changes: 2 additions & 0 deletions goscord/gateway/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (s *Session) registerHandlers() {
event.EventInteractionCreate: &InteractionCreateHandler{},
event.EventVoiceStateUpdate: &VoiceStateUpdateHandler{},
event.EventVoiceServerUpdate: &VoiceServerUpdateHandler{},

event.EventMessageReactionAdd: &MessageReactionHandler{},
}
}

Expand Down
19 changes: 17 additions & 2 deletions goscord/rest/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"errors"
"fmt"
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/Goscord/goscord/goscord/discord/builder"
"github.com/bytedance/sonic"
"io"
"mime/multipart"
"os"
)

type ChannelHandler struct {
Expand Down Expand Up @@ -38,6 +37,22 @@ func (ch *ChannelHandler) GetChannel(channelId string) (*discord.Channel, error)
return channel, nil
}

// GetMessages gets messages from a channel
func (ch *ChannelHandler) GetMessages(channelId string, limit int) ([]*discord.Message, error) {
data, err := ch.rest.Request(fmt.Sprintf(EndpointGetChannelMessages, channelId), "GET", nil, "application/json")
if err != nil {
return nil, err
}

var messages []*discord.Message
err = sonic.Unmarshal(data, &messages)
if err != nil {
return nil, err
}

return messages, nil
}

// GetMessage gets a message from a channel
func (ch *ChannelHandler) GetMessage(channelId, messageId string) (*discord.Message, error) {
res, err := ch.rest.Request(fmt.Sprintf(EndpointGetChannelMessage, channelId, messageId), "GET", nil, "application/json")
Expand Down
1 change: 0 additions & 1 deletion goscord/rest/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"github.com/Goscord/goscord/goscord/discord"
"github.com/Goscord/goscord/goscord/discord/embed"
"github.com/bytedance/sonic"
)

Expand Down