-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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