cs-codex-dist-tests/Tools/BiblioTech/Options/FileAttachementOption.cs

31 lines
941 B
C#
Raw Normal View History

2023-10-24 13:25:45 +00:00
using Discord;
namespace BiblioTech.Options
{
public class FileAttachementOption : CommandOption
{
public FileAttachementOption(string name, string description, bool isRequired)
: base(name, description, type: ApplicationCommandOptionType.Attachment, isRequired)
{
}
public async Task<IAttachment?> Parse(CommandContext context)
{
var fileOptionData = context.Options.SingleOrDefault(o => o.Name == Name);
if (fileOptionData == null)
{
2023-10-25 08:54:26 +00:00
await context.Followup("Attachement option not received.");
2023-10-24 13:25:45 +00:00
return null;
}
var attachement = fileOptionData.Value as IAttachment;
if (attachement == null)
{
2023-10-25 08:54:26 +00:00
await context.Followup("Attachement is null or empty.");
2023-10-24 13:25:45 +00:00
return null;
}
return attachement;
}
}
}