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

