lundi 6 décembre 2021

How to count repeating functions in a for loop, Discord.py

I am trying to create a Discord slot bot where if 2 of the emojis match the bot rewards the user a prize and if all 3 then multiply the prize by 3x. However in order to do this I need to check and see if my function is repeating any values, ive looked online for an answer and the closed thing I found to what I think I needed was .count if description_text.count(i): and then if two or more matched payout x2 etc. but since my function is a int and not a string it does not work. I also tried counting the list but at last that only returned false since the list is unique.

I was wondering if you anyone had any insight on how I might be able to see if the emojis are repeating and then if they are payout the prizes accordingly. Thanks!

final = [
    "||:watermelon:||", #0
    "||:lemon:||", #1
    "||:tangerine:||", #2
    "||:apple:||", #3
    "||:pineapple:||", #4
]

description_text = ""

for i in range(3):
    description_text = f"{description_text} {random.choices(final, cum_weights=(0.4, 0.4, 0.2, 0.2, 0.2), k=1)[0]}"
    
embed = discord.Embed(title="Slot Machine", description= description_text, color=0x00d9ff)
embed.set_footer(text="Use !lottery to see how Prizes work!")
await ctx.send(embed=embed)

if description_text.count(i):
    await update_bank(ctx.author,2*amount)
    await ctx.send(f'You won :slight_smile: {ctx.author.mention}')
else:
    await update_bank(ctx.author,-1*amount)
    await ctx.send(f'You lose :slight_frown: {ctx.author.mention}')

Error Message: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: must be str, not int




Aucun commentaire:

Enregistrer un commentaire