Hi all,
I'm migrating from discord.js to discord.net, I was wondering if there is a way to keep stateful date in a command class?
So this data would be present every run, I noticed that commands are by default transient, so not sure how to go about this.
Using dependency injection btw:
{
GatewayIntents = GatewayIntents.Guilds | GatewayIntents.GuildMessages | GatewayIntents.GuildMembers | GatewayIntents.DirectMessages
}));
services.AddHostedService<StartupService>();
services.AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()));
services.AddSingleton<InteractionHandler>();
services.AddSingleton<DiscordLogger>();
services.AddSingleton<PingCommand>();
public sealed class PingCommand : InteractionModuleBase
{
private readonly ILogger<PingCommand> _logger;
private string test;
public PingCommand(ILogger<PingCommand> logger, InteractionHandler interactionHandler)
{
_logger = logger;
test = "FIRST";
}
// This command will look like
// group-name ping
[SlashCommand("ping", "Get a pong")]
public async Task Ping()
{
test = "SECOND";
await Context.Interaction.RespondAsync("pong1");
}
// This command will look like
// group-name ping
[SlashCommand("ping2", "Get a pong")]
public async Task Ping2()
{
await Context.Interaction.RespondAsync(test);
}
}
Best regards!