Esli Stavenga Esli Stavenga - 1 month ago 18
C# Question

Trying to send random string in C# Discord

I am trying to make a bot in Discord. I now am working on making a random url. And to make this url, I first want to be sure the random generator works good. The random generated chars will be outputted as an array, but I want it as a string but I do not know how. I want the bot to send "LinkString" whenever I type +meme. Here is my code:

{
commands.CreateCommand("meme")
.Do(async (e) =>
{
await e.Channel.SendMessage(LinkString);
});
}

discord.ExecuteAndWait(async () =>
{

});
}

private string LinkString(int Size)
{
string input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var chars = Enumerable.Range(0, Size)
.Select(x => input[random.Next(0, input.Length)]);
return new string(chars.ToArray());
}

Answer

You need to give your LinkString() method a parameter, an int as you've specified. Change it to this:

 await e.Channel.SendMessage(LinkString(5));