'Coinflip Embed Command Discord.py?
How would I go about making a coinflip embed command. What I want it to do is make a discord embed saying Coinflip | (Bot Name) as the header, then the field is "(User who used the command) the coin landed on (what it lands on)! and then the thumbnail is a picture of a coin flipped on tails or heads.
Solution 1:[1]
Method
You can import choice from random, and use the number 1 and 0 to make determine your coinflip by doing something like if random.choice(number) == 1:
.
Example
import random
from random import choice
determine_flip = [1, 0]
@bot.commands()
async def coinflip(ctx):
if random.choice(determine_flip) == 1:
embed = discord.Embed(title="Coinflip | (Bot Name)", description=f"{ctx.author.mention} Flipped coin, we got **Heads**!")
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="Coinflip | (Bot Name)", description=f"{ctx.author.mention} Flipped coin, we got **Tails**!")
await ctx.send(embed=embed)
Conclusion
I hope this helped, good luck on your Discord Bot, If you're new to discord.py then you can get help from my community and improve your bot and even solve your problems.
Have a nice day!
Join Senarc if you need help. ;)
Solution 2:[2]
async def _coinflipl(ctx):
responses = ['heads.',
'tails.']
await ctx.send(f"{random.choice(responses)}") ```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Damon |