added dm channel support.

This commit is contained in:
5elenay
2021-08-28 18:38:26 +03:00
parent a2e5584d93
commit 10de8762c7
4 changed files with 47 additions and 61 deletions

16
user.go
View File

@@ -1,6 +1,7 @@
package revoltgo
import (
"encoding/json"
"time"
"github.com/oklog/ulid/v2"
@@ -56,3 +57,18 @@ func (u *User) CalculateCreationDate() error {
func (u User) FormatMention() string {
return "<@" + u.Id + ">"
}
// Create a DM with the user.
func (u User) CreateDirectMessage() (*Channel, error) {
dmChannel := &Channel{}
dmChannel.Client = u.Client
resp, err := u.Client.Request("GET", "/users/"+u.Id+"/dm", []byte{})
if err != nil {
return dmChannel, err
}
err = json.Unmarshal(resp, dmChannel)
return dmChannel, err
}