當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.GuildMemberMove方法代碼示例

本文整理匯總了Golang中github.com/bwmarrin/discordgo.Session.GuildMemberMove方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.GuildMemberMove方法的具體用法?Golang Session.GuildMemberMove怎麽用?Golang Session.GuildMemberMove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/bwmarrin/discordgo.Session的用法示例。


在下文中一共展示了Session.GuildMemberMove方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: banUser

func banUser(s *discordgo.Session, guild *discordgo.Guild,
	author *discordgo.Member, channelID string, arr []string) {
	if len(arr) == 4 && len(arr[2]) == 21 &&
		checkForPermissions(s, channelID, author.Roles) {
		arr[2] = arr[2][2 : len(arr[2])-1]
		userRole := ""
		username := ""
		for _, member := range guild.Members {
			if arr[2] == member.User.ID {
				username = member.User.Username
				userRole = member.Roles[0]
				break
			}
		}
		duration, _ := (strconv.Atoi(arr[3]))

		pgDb := dbConn()
		tx, err := pgDb.Begin()
		checkErr(err)

		rows, err := tx.Query(
			`SELECT duration FROM bans 
			WHERE user_id = $1`, arr[2])
		checkErr(err)

		var (
			dur int
			i   int
		)

		for rows.Next() {
			i++
			rows.Scan(&dur)
		}
		rows.Close()
		if i == 0 {

			_, err = tx.Exec(
				`INSERT INTO bans(name, time_stamp, duration,
				guild_id, role_id, user_id)
				VALUES($1, $2, $3, $4, $5, $6)`,
				username, int64(time.Now().Unix()),
				duration*60, guild.ID, userRole, arr[2])
			checkErr(err)

			s.GuildMemberEdit(guild.ID, arr[2], []string{roleBannedId})
			for _, c := range guild.Channels {
				if c.Name == "AFK" {
					s.GuildMemberMove(guild.ID, arr[2], c.ID)
					break
				}
			}
			s.ChannelMessageSend(channelID,
				fmt.Sprintf(
					"User %s has been temporary banned for %d minute(s)",
					username, duration))
		} else {
			_, err = tx.Exec(
				`UPDATE bans SET duration = $1
				WHERE user_id = $2`, dur+duration*60, arr[2])
			checkErr(err)

			s.ChannelMessageSend(channelID,
				fmt.Sprintf(
					"Users %s temporary ban has been extended by %d minute(s)",
					username, duration))
		}
		tx.Commit()
		pgDb.Close()
	} else {
		s.ChannelMessageSend(channelID,
			fmt.Sprintf("Please check the parameters"))
	}
}
開發者ID:Muckfoot,項目名稱:Go,代碼行數:74,代碼來源:basic_bot.go


注:本文中的github.com/bwmarrin/discordgo.Session.GuildMemberMove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。