forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createinvite.go
55 lines (48 loc) · 1.39 KB
/
createinvite.go
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
51
52
53
54
55
package createinvite
import (
"github.com/jonas747/dcmd"
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/stdcommands/util"
)
var Command = &commands.YAGCommand{
Cooldown: 2,
CmdCategory: commands.CategoryDebug,
HideFromCommandsPage: true,
Name: "createinvite",
Description: "Maintenance command, creates a invite for the specified server",
HideFromHelp: true,
RequiredArgs: 1,
Arguments: []*dcmd.ArgDef{
{Name: "server", Type: dcmd.Int},
},
RunFunc: util.RequireBotAdmin(func(data *dcmd.Data) (interface{}, error) {
channels, err := common.BotSession.GuildChannels(data.Args[0].Int64())
if err != nil {
return nil, err
}
channelID := int64(0)
for _, v := range channels {
if channelID == 0 || v.Type != discordgo.ChannelTypeGuildVoice {
channelID = v.ID
if v.Type != discordgo.ChannelTypeGuildVoice {
break
}
}
}
if channelID == 0 {
return "No possible channel :(", nil
}
invite, err := common.BotSession.ChannelInviteCreate(channelID, discordgo.Invite{
MaxAge: 120,
MaxUses: 1,
})
if err != nil {
return nil, err
}
bot.SendDM(data.Msg.Author.ID, "discord.gg/"+invite.Code)
return "Sent invite expiring in 120 seconds and with 1 use in DM", nil
}),
}