V4NSH4J / discord-mass-DM-GO

The most powerful Discord selfbot written in GO allowing users to automate their campaigns & send low-cost mass messages to Discord users!
https://t.me/tosviolators
GNU Affero General Public License v3.0
2.17k stars 637 forks source link

Update presence causes Unknown Opcode error #691

Open gameveloster opened 2 years ago

gameveloster commented 2 years ago

I'm trying to modify this amazing software so that it can update the presence to "dnd", and do this separately from the initial IDENTIFY request when opening a websocket connection.

I tried having something like this:

// token_onliner.go
go func(i int) {
    instance := instances[i]
    err := instance.StartWS()
    if err != nil {
        color.Red("[%v] Error while opening websocket: %v", time.Now().Format("15:04:05"), err)
    } else {
        color.Green("[%v] Websocket opened %v", time.Now().Format("15:04:05"), instance.CensorToken())
    }

    err = instance.PresenceChanger("dnd", false)
    if err != nil {
        color.Red("[%v]][X] %v Error while changing presence: %v", time.Now().Format("15:04:05"), instance.CensorToken(), err)
        return
    }
    wg.Done()
}(i)
// token_util.go
func (in *Instance) PresenceChanger(status string, afk bool) error {
    err := in.Ws.Conn.WriteJSON(&Event{
        Op: OpcodePresenceUpdate,
        Data: Data{
            PresenceChange: PresenceChange{
                // Since:      0,
                Activities: []Activity{},
                Status:     status,
                Afk:        afk,
            },
        }})
    if err != nil {
        color.Red("Error while updating presence: %v", err)
    }

    return err
}

and

// types.go
type Activity struct {
    Name string `json:"name"`
    Type int    `json:"type"`
}

type PresenceChange struct {
    Since      int        `json:"since,omitempty"`
    Activities []Activity `json:"activities"`
    Status     string     `json:"status"`
    Afk        bool       `json:"afk"`
}
// protocol.go
type Data struct {
    Message
    Identify
    PresenceChange
        ...
}

but immediately after the first instance is connected online, I get the error

Websocket closed websocket: close 4001: Unknown opcode. OTg3Mzk4MzA4OTE1OT123456.G2K123.1234xStQ9IxoWW************************

I'm very new to Go and Discord, hope someone can help me out here. @V4NSH4J Thanks!

V4NSH4J commented 2 years ago

Hey! thank you for the issue. Your payload and rest of the code is indeed correct, but this whole thing lacks some extra mechanism of switching discord sessions which isn't present in DMDGO's code.

Screenshot 2022-06-20 at 1 03 06 PM

My best guess is, after switching status, Discord sends over the new session ID. When discord does this, they expect us to send them opcode 6 along with our new session ID. It's the same thing they want us to do when a user disconnects from websocket. However, till now, if we got disconnected, we would just open a new websocket which is why code for SESSIONS_REPLACE is not present here.

Alternate way which would work for now is closing websocket and sending your status in the initial identify payload for the gateway to switch or starting from the desired status in the first place!