Skip to content

Instantly share code, notes, and snippets.

@Quahu
Created May 25, 2018 19:37
Show Gist options
  • Select an option

  • Save Quahu/0be7f773191159eb4cc6c0afbd12f3c4 to your computer and use it in GitHub Desktop.

Select an option

Save Quahu/0be7f773191159eb4cc6c0afbd12f3c4 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