#RespondAsync hangs indefinitely

1 messages · Page 1 of 1 (latest)

cyan swan
#

I'm trying to set up a simple bot, but I've got an issue with responding to slash commands.
I've gotten the slash command registered, and the bot receives it, but it hangs indefinitely upon calling await command.RespondAsync("")

It's also throwing this in the debug output:
Exception thrown: 'System.TimeoutException' in System.Private.CoreLib.dll

I suspect that this is a permissions issue, but I'm not sure,

using Discord;
using Discord.WebSocket;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using System;
using System.Threading.Tasks;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer().AddSwaggerGen();

var token = builder.Configuration.GetValue<string>("token") ?? throw new Exception("Missing token");

var discordClient = new DiscordSocketClient();
discordClient.Ready += () =>
{
    Console.WriteLine("Client is ready");
    return Task.CompletedTask;
};
await discordClient.LoginAsync(TokenType.Bot, token);
await discordClient.StartAsync();

discordClient.SlashCommandExecuted += async (SocketSlashCommand command) =>
{
    Console.WriteLine($"Received slash command {command.Id}");
    await command.RespondAsync($"You executed {command.Data.Name}");
    Console.WriteLine($"Responded to slash command {command.Id}");
};

var app = builder.Build();
app.UseSwagger().UseSwaggerUI();
app.MapGet("/hello", () =>
{
    discordClient.SetGameAsync(DateTime.Now.ToString());
    return "Hello";
}).WithOpenApi();
app.Run();

Console output:

Client is ready
Received slash command 1253461048044818433
frozen locust
#

From what it looks like your command isn't going anywhere

#

Also you should probably use interaction framework pwetty

shrewd anchor
#

Sync your system clock

cyan swan
#

I'll try syncing the system clock when I get home, but the program logs that it received command very quickly after it's sent from discord.

cyan swan
past holly
#

I've done this same thing way too many times pain