fixed message context interaction

This commit is contained in:
2024-04-07 16:02:30 +02:00
parent 5f2fc7cbf1
commit 9e613d5adc
2 changed files with 12 additions and 5 deletions

View File

@@ -48,7 +48,7 @@ var cmd_tag Command = Command{
case "get":
GetTagCommand(e)
case "add":
AddTagCommand(e, "")
AddTagCommand(e)
case "remove":
removeTag(e.GuildID().String(), e.SlashCommandInteractionData().String("tag"))
err := e.CreateMessage(discord.NewMessageCreateBuilder().
@@ -103,7 +103,7 @@ var context_tag Command = Command{
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild),
},
Interact: func(e *events.ApplicationCommandInteractionCreate) {
AddTagCommand(e, e.SlashCommandInteractionData().String(""))
AddTagCommand(e)
},
}
@@ -116,7 +116,11 @@ func GetTagCommand(e *events.ApplicationCommandInteractionCreate) {
}
}
func AddTagCommand(e *events.ApplicationCommandInteractionCreate, prevalue string) {
func AddTagCommand(e *events.ApplicationCommandInteractionCreate) {
var prevalue string
if e.ApplicationCommandInteraction.Data.Type() == discord.ApplicationCommandTypeMessage {
prevalue = e.MessageCommandInteractionData().TargetMessage().Content
}
err := e.Modal(discord.ModalCreate{
CustomID: "tag_add_modal" + e.User().ID.String(),
Title: "Add a custom tag command",

View File

@@ -62,11 +62,14 @@ func ready(e *events.Ready) {
func applicationCommandInteractionCreate(e *events.ApplicationCommandInteractionCreate) {
for _, command := range commands {
if command.Interact != nil && e.SlashCommandInteractionData().CommandName() == command.Definition.CommandName() {
if command.Interact != nil && e.Data.CommandName() == command.Definition.CommandName() {
if !command.AllowDM && e.ApplicationCommandInteraction.GuildID().String() == "" {
e.CreateMessage(discord.NewMessageCreateBuilder().
err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent("This command is not available in DMs.").SetEphemeral(true).
Build())
if err != nil {
logrus.Error(err)
}
} else {
command.Interact(e)
}