本文整理汇总了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)
}