本文整理汇总了Golang中github.com/bwmarrin/discordgo.Session.User方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.User方法的具体用法?Golang Session.User怎么用?Golang Session.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.User方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Welcome
//Welcome sends an acknowledge to the terminal that it is listening, and prints the current Username
func Welcome(dg *discordgo.Session) {
d := color.New(color.FgYellow, color.Bold)
d.Printf("Listening!\n\n")
user, _ := dg.User("@me")
d.Printf("Welcome, %s!\n\n", user.Username)
}
示例2: fetchUser
func fetchUser(sess *discordgo.Session, userid string) *discordgo.User {
var result *discordgo.User
retryOnBadGateway(func() error {
var err error
result, err = sess.User(userid)
if err != nil {
return err
}
return nil
})
return result
}
示例3: manualUnban
func manualUnban(s *discordgo.Session, channelID string,
roleID []string, arr []string) {
if checkForPermissions(s, channelID, roleID) &&
len(arr) == 3 && len(arr[2]) == 21 {
arr[2] = arr[2][2 : len(arr[2])-1]
pgDb := dbConn()
tx, err := pgDb.Begin()
checkErr(err)
user, _ := s.User(arr[2])
name := user.Username
rows, err := tx.Query(
"SELECT id, guild_id, role_id FROM bans WHERE name = $1", name)
checkErr(err)
flag := false
for rows.Next() {
flag = true
var id, guild_id, role_id string
rows.Scan(&id, &guild_id, &role_id)
if len(guild_id) != 0 {
rows.Close()
_, err = tx.Exec("DELETE FROM bans WHERE id = $1", id)
checkErr(err)
s.GuildMemberEdit(guild_id, arr[2], []string{role_id})
s.ChannelMessageSend(channelID,
fmt.Sprintf("User %s has been unbanned", name))
break
}
}
tx.Commit()
pgDb.Close()
if flag == false {
s.ChannelMessageSend(channelID,
fmt.Sprintf("User %s is not banned", name))
}
} else {
s.ChannelMessageSend(channelID,
fmt.Sprintf("Please check the parameters"))
}
}