-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.go
More file actions
39 lines (34 loc) · 982 Bytes
/
Copy pathping.go
File metadata and controls
39 lines (34 loc) · 982 Bytes
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
package main
import (
"fmt"
"log"
"github.com/bwmarrin/discordgo"
)
// Pingスラッシュコマンドを登録
func SlashCommand(s *discordgo.Session) {
s.AddHandler(handlePing)
cmd := &discordgo.ApplicationCommand{
Name: "ping",
Description: "Reply with Pong!",
}
// 登録
_, err := s.ApplicationCommandCreate(s.State.User.ID, "", cmd)
if err != nil {
log.Fatalf("Error: Failed to create slash command: %v", err)
}
}
// Pingスラッシュコマンドの処理
func handlePing(s *discordgo.Session, i *discordgo.InteractionCreate) {
if i.ApplicationCommandData().Name != "ping" {
return
}
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("Pong! (%dms)", s.HeartbeatLatency().Milliseconds()),
},
})
if err != nil {
log.Printf("Error: Failed to respond to ping command: %v", err)
}
}