Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support of Stage Instance REST API and Events (#1158)
* feat: Add support of StageInstance RESTAPI and Events * chore: Make the changes for following the current convention of package * doc: Add missing docs and example for stage-instance * doc: Add final log for deleted stage instance * refactor: Prevent trailing slash on stage instance endpoint * chore: Harmonize params structure * Update structs.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * docs: Remove deprecated doc * docs: Add new documentation for restapi function * Update structs.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Update structs.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Update restapi.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Update structs.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Update structs.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * doc: Add sleep in example to let user see by themselves Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
- Loading branch information
1 parent
b138df6
commit 8a126aa
Showing
6 changed files
with
247 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// Flags | ||
var ( | ||
GuildID = flag.String("guild", "", "Test guild ID") | ||
StageChannelID = flag.String("stage", "", "Test stage channel ID") | ||
BotToken = flag.String("token", "", "Bot token") | ||
) | ||
|
||
func init() { flag.Parse() } | ||
|
||
// To be correctly used, the bot needs to be in a guild. | ||
// All actions must be done on a stage channel event | ||
func main() { | ||
s, _ := discordgo.New("Bot " + *BotToken) | ||
s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) { | ||
fmt.Println("Bot is ready") | ||
}) | ||
|
||
err := s.Open() | ||
if err != nil { | ||
log.Fatalf("Cannot open the session: %v", err) | ||
} | ||
defer s.Close() | ||
|
||
// Create a new Stage instance on the previous channel | ||
si, err := s.StageInstanceCreate(&discordgo.StageInstanceParams{ | ||
ChannelID: *StageChannelID, | ||
Topic: "Amazing topic", | ||
PrivacyLevel: discordgo.StageInstancePrivacyLevelGuildOnly, | ||
SendStartNotification: true, | ||
}) | ||
if err != nil { | ||
log.Fatalf("Cannot create stage instance: %v", err) | ||
} | ||
log.Printf("Stage Instance %s has been successfully created", si.Topic) | ||
|
||
// Edit the stage instance with a new Topic | ||
si, err = s.StageInstanceEdit(*StageChannelID, &discordgo.StageInstanceParams{ | ||
Topic: "New amazing topic", | ||
}) | ||
if err != nil { | ||
log.Fatalf("Cannot edit stage instance: %v", err) | ||
} | ||
log.Printf("Stage Instance %s has been successfully edited", si.Topic) | ||
|
||
time.Sleep(5 * time.Second) | ||
if err = s.StageInstanceDelete(*StageChannelID); err != nil { | ||
log.Fatalf("Cannot delete stage instance: %v", err) | ||
} | ||
log.Printf("Stage Instance %s has been successfully deleted", si.Topic) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters