本文整理匯總了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"))
}
}