Skip to content

Instantly share code, notes, and snippets.

@dterracino
Forked from Quahu/randomimage.cs
Last active February 12, 2020 01:06
Show Gist options
  • Save dterracino/33e5f2a8eae9625dee7cd54faf42ef2f to your computer and use it in GitHub Desktop.
Save dterracino/33e5f2a8eae9625dee7cd54faf42ef2f to your computer and use it in GitHub Desktop.
An example command that sends a random image from a predefined array each time it's used.
// define a static array of paths that we'll choose the image from
// we make it static so it isn't reinstantiated unnecessarily each time we run a command from this module
private static string[] _imagePaths = new[] { "images/hackerman.jpg", "images/computerman.jpg", "images/polarbear.png" };
[Command("image")]
[Alias("picture")]
[Summary("Sends a random image.")]
public async Task ImageAsync()
{
// using a new instance of the Random class we randomize a path with an index from 0 to x - 1, where x is the amount of paths in the array
var image = _imagePaths[new Random().Next(_imagePaths.Length)];
// we send the image
await Context.Channel.SendFileAsync(image);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment