/
events.go
77 lines (64 loc) · 2 KB
/
events.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package events
import (
"github.com/bwmarrin/discordgo"
)
func MessageCreate(session *discordgo.Session, message *discordgo.MessageCreate) {
if message.Author.ID == session.State.User.ID {
return
}
if message.Content == ".ping" {
_, err := session.ChannelMessageSend(message.ChannelID, "Olá")
if err != nil {
session.ChannelMessageSend(message.ChannelID, "Falhou")
}
}
}
func InteractionCreate(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
if interaction.Type == discordgo.InteractionApplicationCommand {
answerCommand(session, interaction)
return
}
if interaction.Type == discordgo.InteractionMessageComponent {
content := "Obrigado pelo feedback "
switch interaction.MessageComponentData().CustomID {
case "yes_btn":
content += "(yes)"
case "no_btn":
content += "(no)"
}
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseUpdateMessage,
Data: &discordgo.InteractionResponseData{
Content: content,
Components: []discordgo.MessageComponent{},
},
})
}
}
func answerCommand(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
yes_button := discordgo.Button{
Label: "Sim",
Style: discordgo.SuccessButton,
Disabled: false,
CustomID: "yes_btn",
}
no_button := discordgo.Button{
Label: "Não",
Style: discordgo.DangerButton,
Disabled: false,
CustomID: "no_btn",
}
components := []discordgo.MessageComponent{ yes_button, no_button }
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Você está satisfeito com os botões?",
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{ Components: components },
},
},
})
if err != nil {
panic(err)
}
}