Socialify

Folder ..

Viewing kick.go
49 lines (41 loc) • 1.3 KB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package admin

import (
	//"fmt"
	"log"
	//"time"

	"yuzaki/utils"

	"github.com/bwmarrin/discordgo"
)

func KickMember(s *discordgo.Session, i *discordgo.InteractionCreate) {
	err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
		Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
		Data: &discordgo.InteractionResponseData{
			Flags: discordgo.MessageFlagsEphemeral,
		},
	})
	if err != nil {
		log.Printf("Error responding to interaction: %s. Interaction: purge. Interaction By: %s\n", err, i.Member.DisplayName())
		return
	}

	options := i.ApplicationCommandData().Options
	optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
	for _, option := range options {
		optionMap[option.Name] = option
	}

	option, ok := optionMap["target"]
	if !ok {
		utils.SendFollowUpMessage(s, i, "You must mention the user to kick!", true)
		return
	}

	user := option.UserValue(s);
	if user == nil {
		utils.SendFollowUpMessage(s, i, "Invalid user", true)
		return
	}
		err = s.GuildMemberDeleteWithReason(i.GuildID, user.ID, "Kicked by an admin")
	if err != nil {
		utils.SendFollowUpMessage(s, i, "Could not kick user", true)
		return
	}

	utils.SendFollowUpMessage(s, i, "User kicked successfully!", true)
	
}