Add Kick command

pull/1/head
DustyP 6 years ago
parent ad7fc5bde0
commit 81ffdc0a74

@ -0,0 +1,53 @@
package exts
import (
"errors"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman"
"strings"
)
func kickUser(ctx disgoman.Context, args []string) {
var member *discordgo.Member
var err error
if len(ctx.Message.Mentions) > 0 {
member, err = ctx.Session.GuildMember(ctx.Guild.ID, ctx.Message.Mentions[0].ID)
} else {
member, err = ctx.Session.GuildMember(ctx.Guild.ID, args[0])
}
if err != nil {
ctx.ErrorChannel <- disgoman.CommandError{
Context: ctx,
Message: "Couldn't get that member",
Error: err,
}
return
}
if !disgoman.HasHigherRole(ctx.Session, ctx.Guild.ID, ctx.Message.Author.ID, member.User.ID) {
ctx.ErrorChannel <- disgoman.CommandError{
Context: ctx,
Message: "You must have a higher role than the person you are trying to kick",
Error: errors.New("need higher role"),
}
return
}
if !disgoman.HasHigherRole(ctx.Session, ctx.Guild.ID, ctx.User.ID, member.User.ID) {
ctx.ErrorChannel <- disgoman.CommandError{
Context: ctx,
Message: "I don't have a high enough role to kick that person",
Error: errors.New("need higher role"),
}
return
}
if len(args) > 1 {
err = ctx.Session.GuildMemberDeleteWithReason(ctx.Guild.ID, member.User.ID, strings.Join(args[1:], " "))
} else {
err = ctx.Session.GuildMemberDelete(ctx.Guild.ID, member.User.ID)
}
if err != nil {
}
}

@ -4,7 +4,7 @@ go 1.14
require ( require (
github.com/bwmarrin/discordgo v0.20.2 github.com/bwmarrin/discordgo v0.20.2
github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130 github.com/dustinpianalto/disgoman v0.0.0-20200420022152-4729d2c5ee3e
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lib/pq v1.3.0 github.com/lib/pq v1.3.0
) )

@ -4,6 +4,8 @@ github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100 h1:yKyt6Ea
github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130 h1:J967RgBA9J1nBJrNdVxpYeRNYAoA2h5XOc0ndD6zhQQ= github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130 h1:J967RgBA9J1nBJrNdVxpYeRNYAoA2h5XOc0ndD6zhQQ=
github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
github.com/dustinpianalto/disgoman v0.0.0-20200420022152-4729d2c5ee3e h1:EeLjjVHZNa9DCpOftoKDZalSwO7usn9yhRwXXz2RSdA=
github.com/dustinpianalto/disgoman v0.0.0-20200420022152-4729d2c5ee3e/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=

Loading…
Cancel
Save