@@ -18,12 +18,12 @@ const (
18
18
19
19
// TryHackMeCmd encapsulates all logic for the `/share` command.
20
20
type TryHackMeCmd struct {
21
- GuildID string
21
+ GuildID , channelID string
22
22
}
23
23
24
24
// NewTryHackMeCmd returns a new command handler.
25
- func NewTryHackMeCmd (guildID string ) * TryHackMeCmd {
26
- return & TryHackMeCmd {GuildID : guildID }
25
+ func NewTryHackMeCmd (guildID , chanID string ) * TryHackMeCmd {
26
+ return & TryHackMeCmd {GuildID : guildID , channelID : chanID }
27
27
}
28
28
29
29
// RegisterCommand registers/updates the slash-command every time the bot becomes READY.
@@ -43,12 +43,22 @@ func (c *TryHackMeCmd) RegisterCommand(s *discordgo.Session) error {
43
43
// It processes both the slash-command invocation and the modal submit event.
44
44
func (c * TryHackMeCmd ) Handle (s * discordgo.Session , i * discordgo.InteractionCreate ) {
45
45
switch i .Type {
46
-
47
46
case discordgo .InteractionApplicationCommand :
48
47
if i .ApplicationCommandData ().Name != cmdName {
49
48
return
50
49
}
51
-
50
+ if i .ChannelID != c .channelID {
51
+ if err := s .InteractionRespond (i .Interaction , & discordgo.InteractionResponse {
52
+ Type : discordgo .InteractionResponseChannelMessageWithSource ,
53
+ Data : & discordgo.InteractionResponseData {
54
+ Content : "このコマンドはこのチャンネルでは使用できません。" ,
55
+ Flags : discordgo .MessageFlagsEphemeral ,
56
+ },
57
+ }); err != nil {
58
+ log .Printf ("tryhackme: respond error: %v" , err )
59
+ }
60
+ return
61
+ }
52
62
// Send modal
53
63
modal := & discordgo.InteractionResponse {
54
64
Type : discordgo .InteractionResponseModal ,
0 commit comments