Nelson
Nelson
CC#
Created by Nelson on 12/13/2023 in #help
Add console application to (see image)
No description
3 replies
CC#
Created by Nelson on 11/18/2023 in #help
✅ 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
};
}
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
};
}
2 replies
CC#
Created by Nelson on 11/15/2023 in #help
Discord bot command that sends local images
Hello! Does anyone know how to make a discord bot command that is able to send locally stored images. I've seen the method 'SendFileAsync' being used, but it seems like it is unavailable to me in my VS2022. Is it only available in a specific package or? Any help appreciated!
8 replies