Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Chance to fail at rob command. (discordpy)

Okay so im making a currency bot, and im stuck at the rob command.
Is that possible to add "chances" to the code? i mean that when someone executes the command then ex: 45% that the robbery will not succeed? If yes, then how?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

yes, there is a way to do randomness in python. It is to use the random module.
Here’s the rob command example :

@bot.command()
async def rob(ctx):
    if random.randint(0, 100) <= 45:
        await ctx.send("Robbery has failed.")
    else:
        await ctx.send("Robbery was successful.")

Result :
result

Don’t forget to add import random in your code before referencing it, preferably add it at the top of your code

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading