bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.11k stars 816 forks source link

Occasionally errors will occur when calling discordgo.Session.InteractionRespond #1505

Closed houxul closed 8 months ago

houxul commented 8 months ago

Calling discordgo.Session.InteractionRespond in the slash command handler will occasionally report 'HTTP 404 Not Found, {"message": "Unknown interaction", "code": 10062}'

example


func main() {
    sess, err := discordgo.New("Bot " + conf.Conf.BotToken)
    if err != nil {
        glog.Fatalf("Invalid bot parameters: %v", err)
    }

    sess.AddHandler(CommandHandler)

    // do something
}

func CommandHandler(sess *discordgo.Session, i *discordgo.InteractionCreate) {
    interactionBytes, err := json.Marshal(i.Interaction)
    if err != nil {
        glog.Errorf("json marshal interaction error: %v", err)
        return
    }
    glog.V(8).Infof("Received interaction: %v", string(interactionBytes))

    content := fmt.Sprintf("<@%v> -Task has been received", user.ID)
    if err := sess.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
        Type: discordgo.InteractionResponseChannelMessageWithSource,
        Data: &discordgo.InteractionResponseData{
            Content: content,
        },
    }); err != nil {
        glog.Errorf("respond to interaction: %v error: %v", i.Interaction.ID, err)
        return
    }
    // do something
}
houxul commented 8 months ago

discordgo version v0.27.1

FedorLap2006 commented 8 months ago

Please check that you're not running multiple bot instances, as this is usually the case with such error

houxul commented 8 months ago

Please check that you're not running multiple bot instances, as this is usually the case with such error

Hello, I confirmed that there is only one bot instance running

houxul commented 8 months ago

It's a problem on my side. I did start multiple instances here. I'm very sorry.

FedorLap2006 commented 8 months ago

No problem! Happens to the best of us.