Gamble bot is a bot that you can chat with and ask to play games of odds with you or solve simple equations as a bonus. The games you can play with gamble bot are: Coinflip and Roll, with coinflip the bot chooses randomly between Heads or Tails. With Roll the bot chooses a random number between 1 and 100.
This is the first discord bot i created with the help of a tutorial on youtube. The things i strugled most with was setting up the code in visual studio, using a custom library for the bot and coding in general. I also used .NET but i honestly did not really knew what i was doing on that part because it is really hard to learn. I had fun with this project and would do it again sometime in the future.
• Coinflip
• Roll
• Command list
• Json reader
• simple equations
[Command("coinflip")]
public async Task CoinFlipAsync(CommandContext ctx)
{
string result = _random.Next(2) == 0 ? "Heads" : "Tails";
await ctx.RespondAsync($"🪙 The coin landed on: **{result}**!");
}
the user types "!coinflip" and the bot flips the coin with a random outcome
[Command("roll")]
public async Task RollAsync(CommandContext ctx)
{
int randomNumber = _random.Next(1, 101);
await ctx.RespondAsync($"🎲 You rolled a **{randomNumber}**!");
}
The user types "roll" and the bot chooses a random number between 1 and 100
internal class Jsonreader
{
public string token { get; set; }
public string prefix { get; set; }
public async Task ReadJSON()
{
using (StreamReader sr = new StreamReader("config.json"))
{
string json = await sr.ReadToEndAsync();
JSONStructure data = JsonConvert.DeserializeObject(json);
this.token = data.token;
this.prefix = data.prefix;
}
}
}
internal sealed class JSONStructure
{
public string token { get; set; }
public string prefix { get; set; }
}
The Json reader is specifically made to load the bot token and read the prefix of the Discord bot
Project Type: Discord bot
Role: Solo Dev
Status: Done