From b51655404a0fb169635be934b02c76d0c00d7226 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Sat, 2 Sep 2023 01:38:18 +0300 Subject: [PATCH] feat: add UpdateCustomStatus (#1425) Add Session.UpdateCustomStatus, which allows to set and reset the custom status of a bot. --- wsapi.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wsapi.go b/wsapi.go index 9ef6dd0..f63cfdb 100644 --- a/wsapi.go +++ b/wsapi.go @@ -389,6 +389,26 @@ func (s *Session) UpdateListeningStatus(name string) (err error) { return s.UpdateStatusComplex(*newUpdateStatusData(0, ActivityTypeListening, name, "")) } +// UpdateCustomStatus is used to update the user's custom status. +// If state!="" then set the custom status. +// Else, set user to active and remove the custom status. +func (s *Session) UpdateCustomStatus(state string) (err error) { + data := UpdateStatusData{ + Status: "online", + } + + if state != "" { + // Discord requires a non-empty activity name, therefore we provide "Custom Status" as a placeholder. + data.Activities = []*Activity{{ + Name: "Custom Status", + Type: ActivityTypeCustom, + State: state, + }} + } + + return s.UpdateStatusComplex(data) +} + // UpdateStatusComplex allows for sending the raw status update data untouched by discordgo. func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) { // The comment does say "untouched by discordgo", but we might need to lie a bit here.