[Bug]: InvalidOperationException in IDiscordInteraction.RespondAsync (New Issue)
See original GitHub issueCheck 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:
- Created 4 months ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The exception thrown should also have a
Message
property Could you post the message here?I studied the Discord.NET source code and found the solution:
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.