CabbageAdi / DSharpPlus.SlashCommands

An extension for DSharpPlus to make slash commands easier
https://discord.gg/2ZhXXVJYhU
MIT License
44 stars 11 forks source link

Issue with ordering optional arguments #13

Closed crazygmr101 closed 3 years ago

crazygmr101 commented 3 years ago

DSharpPlus 4.0.1 DSharpPlus.SlashCommands 1.2.2

image

The arguments seem to be passed to the command in the order they are defined, regardless of which are actually sent from discord.

In the discord UI, I set title, description, image. The command handler assigned those to content, title, description

Full file for that group:

using System.Net.Mime;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;

public partial class SlashModule : SlashCommandModule
{
    [SlashCommandGroup("message", "Send a message")]
    public class MessageGroup
    {
        [SlashCommand("embed", "Embed a message")]
        public async Task MessageEmbed(
            InteractionContext ctx,
            [Option("Content", "The plain text content of the embed")]
            string content = null,
            [Option("Title", "The title of the embed")]
            string title = null,
            [Option("Description", "The description of the embed")]
            string description = null,
            [Option("Thumbnail", "The thumbnail of the embed")]
            string thumbnail = null,
            [Option("Image", "The image on the bottom of the embed")]
            string image = null)
        {
            if (((await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id)).PermissionsIn(ctx.Channel) &
                 Permissions.SendMessages) == 0)
            {
                await ctx.CreateResponseAsync(
                    InteractionResponseType.ChannelMessageWithSource,
                    new DiscordInteractionResponseBuilder()
                        .AsEphemeral(true)
                        .WithContent("I can't send messages in that channel")
                );
            }

            var embedBuilder = new DiscordEmbedBuilder();

            if (title is not null)
                embedBuilder.WithTitle(title);
            if (description is not null)
                embedBuilder.WithDescription(description);
            if (thumbnail is not null)
                embedBuilder.WithThumbnail(thumbnail);
            if (image is not null)
                embedBuilder.WithImageUrl(image);

            if (content is not null)
                await ctx.Channel.SendMessageAsync(content, embedBuilder.Build());
            else
                await ctx.Channel.SendMessageAsync(embedBuilder.Build());

            await ctx.CreateResponseAsync(
                InteractionResponseType.ChannelMessageWithSource,
                new DiscordInteractionResponseBuilder()
                    .AsEphemeral(true)
                    .WithContent("Sent!"));
        }
    }
}
CabbageAdi commented 3 years ago

Fixed in latest nuget version