Breadcraft-Support/Breadcraft/Commands/RemoveMessageCommand.cs
EmotionChild b658ed8a0a
Commands
2023-01-27 00:42:11 +13:00

41 lines
No EOL
1.1 KiB
C#

using DSharpPlus.Entities;
using System.Threading.Tasks;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
namespace Breadcraft.Commands;
public class RemoveMessageCommand : ApplicationCommandModule
{
[SlashRequireGuild]
[SlashCommand("removemessage", "Removes a message from the 'say' command.")]
public async Task OnExecute(InteractionContext command, [Option("Identifier", "The identifier word used in the /say command.")] string identifier)
{
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "There is no message with that identifier."
}, true);
return;
}
if (Database.RemoveMessage(identifier))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Message removed."
}, true);
}
else
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed removing the message from the database."
}, true);
}
}
}