using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.SlashCommands;
namespace self_bot.commands
{
internal class TestCommand : ApplicationCommandModule
{
private DiscordClient _clientInstance;
public TestCommand(DiscordClient client)
{
_clientInstance = client;
}
private static bool IsOn = false;
[SlashCommand("ToggleTest", "Toggle test messages to be sent at user after every message")]
public async Task Toggle(InteractionContext ctx, [Option("user", "Specified user")] DiscordUser user)
{
IsOn=!IsOn;
if (IsOn==true)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Test toggle online"));
_clientInstance.MessageCreated += TestMessage(user, e);
}
if (IsOn==false)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Test toggle shutting down"));
_clientInstance.MessageCreated -= TestMessage(user, e);
}
}
public async Task TestMessage(DiscordUser user, MessageCreateEventArgs e)
{
if (e.Message.Author.Id == user.Id)
{
await e.Message.RespondAsync("Test success");
}
}
}
}
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.SlashCommands;
namespace self_bot.commands
{
internal class TestCommand : ApplicationCommandModule
{
private DiscordClient _clientInstance;
public TestCommand(DiscordClient client)
{
_clientInstance = client;
}
private static bool IsOn = false;
[SlashCommand("ToggleTest", "Toggle test messages to be sent at user after every message")]
public async Task Toggle(InteractionContext ctx, [Option("user", "Specified user")] DiscordUser user)
{
IsOn=!IsOn;
if (IsOn==true)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Test toggle online"));
_clientInstance.MessageCreated += TestMessage(user, e);
}
if (IsOn==false)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Test toggle shutting down"));
_clientInstance.MessageCreated -= TestMessage(user, e);
}
}
public async Task TestMessage(DiscordUser user, MessageCreateEventArgs e)
{
if (e.Message.Author.Id == user.Id)
{
await e.Message.RespondAsync("Test success");
}
}
}
}