本文整理匯總了Golang中github.com/bwmarrin/discordgo.Session.UserGuilds方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.UserGuilds方法的具體用法?Golang Session.UserGuilds怎麽用?Golang Session.UserGuilds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.UserGuilds方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pollConn
/* may be deprecated by session.Status in discordgo */
func pollConn(s *discordgo.Session) {
c := config.Get()
for {
time.Sleep(10 * time.Second)
found := false
guilds, err := s.UserGuilds()
for _, g := range guilds {
if g.ID == c.Guild {
found = true
break
}
}
if !found {
log.Warningf("Could not find membership matching guild ID. %s", c.Guild)
log.Warningf("Maybe I need a new invite? Using code %s", c.InviteID)
if s.Token != "" {
s.Close()
}
return
}
if err != nil {
log.Warningf("Could not fetch guild info %v", err)
if s.Token != "" {
s.Close()
}
return
}
}
}
示例2: fetchPrimaryTextChannelID
func fetchPrimaryTextChannelID(sess *discordgo.Session) string {
var channelid string
retryOnBadGateway(func() error {
guilds, err := sess.UserGuilds()
if err != nil {
return err
}
guild, err := sess.Guild(guilds[0].ID)
if err != nil {
return err
}
channels, err := sess.GuildChannels(guild.ID)
if err != nil {
return err
}
for _, channel := range channels {
channel, err = sess.Channel(channel.ID)
if err != nil {
return err
}
if channel.Type == "text" {
channelid = channel.ID
return nil
}
}
return errors.New("No primary channel found")
})
return channelid
}
示例3: SetGuildState
//SetGuildState sets the Guild inside the State
func SetGuildState(dg *discordgo.Session) {
State.InsertMode = false
Guilds, _ := dg.UserGuilds()
d := color.New(color.FgYellow, color.Bold)
d.Printf("Select a Guild:\n")
for key, guild := range Guilds {
fmt.Printf("%d:%s\n", key, guild.Name)
}
var response int
fmt.Scanf("%d\n", &response)
State.Guild, _ = dg.Guild(Guilds[response].ID)
Clear()
State.InsertMode = true
}