question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: InvalidOperationException in IDiscordInteraction.RespondAsync (New Issue)

See original GitHub issue

Check The Docs

  • I double checked the docs and couldn’t find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

It was working fine until earlier today: it stopped working with no code change at all. I have updated to the very latest Discord.Net Nuget package (3.10.0), and the issue still occurs, so I assume that something has changed in Discord’s API.

Version

3.10.0

Working Version

3.10.0

Logs

An exception of type System.InvalidOperationException has occurred. Stack trace:
   at Discord.WebSocket.SocketCommandBase.RespondAsync(String text, Embed[] embeds, Boolean isTTS, Boolean ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options)
   at Discord.WebSocket.SocketInteraction.Discord.IDiscordInteraction.RespondAsync(String text, Embed[] embeds, Boolean isTTS, Boolean ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options)
   at Gtacnr.DiscordBot.Global.RespondWithEmbedAsync(IDiscordInteraction interaction, String message, Nullable`1 color, Boolean ephemeral) in C:\Users\Sal\Workspace\Sasinosoft\GTACNR\gta-cnr\discord-bot\Global.cs:line 137
   at Gtacnr.DiscordBot.Moderation.TestCommand.HandleTestSlashCommand(IDiscordInteraction interaction) in C:\Users\Sal\Workspace\Sasinosoft\GTACNR\gta-cnr\discord-bot\TestCommand.cs:line 42
   at Gtacnr.DiscordBot.Services.DiscordInteractionHandler.<>c__DisplayClass7_0.<<ExecuteCommand>b__0>d.MoveNext() in C:\Users\Sal\Workspace\Sasinosoft\GTACNR\gta-cnr\discord-bot\Services\DiscordInteractionHandler.cs:line 124

Sample

Code that causes it


        public static async Task RespondWithEmbedAsync(this IDiscordInteraction interaction, string message, Color? color = null, bool ephemeral = false)
        {
            var embed = new EmbedBuilder()
                .WithDescription(message)
                .WithColor(color ?? Color.Red)
                .Build();
            
            await interaction.RespondAsync(embed: embed, ephemeral: ephemeral);
        }

I have also tried without embed, same result:

        public static async Task RespondWithEmbedAsync(this IDiscordInteraction interaction, string message, Color? color = null, bool ephemeral = false)
        {
            //var embed = new EmbedBuilder()
            //    .WithDescription(message)
            //    .WithColor(color ?? Color.Red)
            //    .Build();
            //
            //await interaction.RespondAsync(embed: embed, ephemeral: ephemeral);

            await interaction.RespondAsync(message);
        }

Packages

Dapper 2.0.123
Discord.Net 3.10.0
Discord.Net.Commands 3.10.0
Discord.Net.Core 3.10.0
Discord.Net.Interactions 3.10.0
Discord.Net.Rest 3.10.0
Discord.Net.Webhook 3.10.0
Discord.Net.WebSocket 3.10.0
Microsoft.Extensions.Configuration 7.0.0
Microsoft.Extensions.Configuration.Binder 7.0.4
Microsoft.Extensions.Configuration.FileExtensions 7.0.0
Microsoft.Extensions.Configuration.Json 7.0.0
Microsoft.Extensions.DependencyInjection 7.0.0
MySqlConnector 2.2.6
Newtonsoft.Json 13.0.3

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Misha-133commented, May 25, 2023

The exception thrown should also have a Message property Could you post the message here?

0reactions
Sasino97commented, Jun 5, 2023

I studied the Discord.NET source code and found the solution:

UseInteractionSnowflakeDate = false

In the DiscordSocketConfig.

If anyone else is wondering: if you change your computer date and time, you need to set that to false otherwise the “DateTime.UtcNow” won’t match the snowflake correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error "System.InvalidOperationException: Cannot add ...
i have this code `using System; using System.Threading.Tasks; using Discord.WebSocket; using Discord.Commands; using Microsoft.Extensions.
Read more >
Discord.Net
I'm currently experiencing an issue with InteractionService.RemoveModuleAsync(TYPE) method (NUGET v3.10.0). When called, the top level type returns true.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found