本文整理匯總了Golang中github.com/bwmarrin/discordgo.Session.GuildChannels方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.GuildChannels方法的具體用法?Golang Session.GuildChannels怎麽用?Golang Session.GuildChannels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.GuildChannels方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: Message
// Message receives a Message struct and sends it to appropriate channels
func Message(s *discordgo.Session, m *types.Message) error {
message := strings.Join(m.Payload, "\n")
var channels []string
var dchannels []*discordgo.Channel
var err error
c := config.Get()
if m.Prefix != "" {
message = fmt.Sprintf("%s: %s", m.Prefix, message)
}
if m.Channels[0] == "*" {
dchannels, err = s.GuildChannels(c.Guild)
if err != nil {
return err
}
//errhandler.Handle(err)
for _, chann := range dchannels {
channels = append(channels, chann.ID)
}
} else {
channels = m.Channels
}
log.Debugf("%s\n", len(channels))
for _, channel := range channels {
s.ChannelMessageSend(channel, message)
}
return nil
}
示例3: discordReadyHandler
//discordReadyHandler sets required data after a successful connection
func discordReadyHandler(s *discordgo.Session, r *discordgo.Ready) {
//Sets this bots name in discordCfg.Name
discordCfg.Name = strings.ToUpper(r.User.Username)
//Iterates through guilds
for _, guild := range r.Guilds {
//Gets a list of channels for this guild
channels, _ := s.GuildChannels(guild.ID)
//Iterates through a list of channels for this guild
for _, channel := range channels {
//If it finds a channel with name 'anime'
//it will add it to discordCfg.AnimeChannels array
//which is used when sending new episode messages in discord
if channel.Name == discordCfg.AnimeChannel {
discordCfg.AnimeChannels = appendUnique(discordCfg.AnimeChannels, channel.ID)
}
}
}
//Logs successful connection to discord was established
log.Println("Connected to discord as", discordCfg.Name)
}