C#C
C#3y ago
Nelson

✅ Is there a way to run a commands method inside of another command? (DSharpPlus)

Title explains it.
c#
        #region RandomImage
        [SlashCommand("randomimage", "Visa en random bild från Örsk Army")]
        public async Task RandomImageAsync(InteractionContext ctx, [Option("mängd", "Ange antal bilder du vill visa")] long amount = 1)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder()
                .WithContent("..."));

            var rand = new Random();
            for (int i = 0; i < amount; i++)
            {
                var files = Directory.GetFiles("H:\\My Drive\\Discord Bot\\Images");
                FileStream file = new FileStream(files[rand.Next(0, files.Length)].ToString(), FileMode.Open);
                var builder = new DiscordMessageBuilder();
                builder.AddFile(file);
                await ctx.Channel.SendMessageAsync(builder);
                await Task.Delay(1000);
            }
        }
        #endregion

        [SlashCommand("test", "test")]
        public async Task Test(InteractionContext ctx)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder()
                .WithContent("..."));

            
            var builder = new DiscordMessageBuilder()
                .WithContent("This message has buttons!")
                .AddComponents(new DiscordComponent[]
                {
                    new DiscordButtonComponent(ButtonStyle.Primary, "1", "This is a button")
                });

            await ctx.Channel.SendMessageAsync(builder);

            Program.client.ComponentInteractionCreated += async (sender, e) =>
            {
                // Run 'RandomImageAsync' Here
            };
        }
Was this page helpful?